cesium shader实现顶点动画

四面体顶点动画实现位移和旋转。

import * as Cesium from 'cesium';// Fragment Shader for Tetrahedron
const fs = `
in vec3 v_positionEC;
in vec3 v_normalEC;
in vec2 v_st;
uniform vec4 color;
uniform float alpha;void main() {vec3 positionToEyeEC = -v_positionEC;vec3 normalEC = normalize(v_normalEC);#ifdef FACE_FORWARDnormalEC = faceforward(normalEC, vec3(0.0, 0.0, 1.0), -normalEC);#endifczm_materialInput materialInput;materialInput.normalEC = normalEC;materialInput.positionToEyeEC = positionToEyeEC;materialInput.st = v_st;vec2 st = materialInput.st;czm_material material = czm_getDefaultMaterial(materialInput);material.alpha = alpha;material.diffuse = color.rgb * 1.5;#ifdef FLATout_FragColor = vec4(material.diffuse + material.emission, material.alpha);#elseout_FragColor = czm_phong(normalize(positionToEyeEC), material, czm_lightDirectionEC);#endif
}
`;// Vertex Shader for Tetrahedron
const vs = `
in vec3 position;
in vec3 normal;
in vec2 st;
in float batchId;
out vec3 v_positionEC;
out vec3 v_normalEC;
out vec2 v_st;
uniform float moveMaxHeight;mat4 rotationAroundZ(float angle)
{float s = sin(angle);float c = cos(angle);return mat4(c,  -s,   0.0, 0.0,s,   c,   0.0, 0.0,0.0, 0.0, 1.0, 0.0,0.0, 0.0, 0.0, 1.0);
}mat4 translationMatrix (float z) {return mat4(1.0, 0.0, 0.0, 0.0,0.0, 1.0, 0.0, 0.0,0.0, 0.0, 1.0, 0.,0.0, 0.0, z, 1.0);
}void main() {// 提取z轴缩放因子float scaleZ = length(czm_model[2].xyz);float uTime = czm_frameNumber * 0.04;float offsetZ = sin(uTime) * moveMaxHeight / 2.;mat4 translationMatrix = translationMatrix(1.0/scaleZ * offsetZ);mat4 rotationMatrix = rotationAroundZ(uTime);vec4 vertex = translationMatrix * rotationMatrix * vec4(position, 1.0);vec4 mvVertex = czm_modelView * vertex;gl_Position = czm_projection * mvVertex;v_positionEC = mvVertex.xyz;v_normalEC = czm_normal * normal;v_st = st;
}
`;export class TetrahedronPrimitive {constructor(options) {this.position = options.position;this.width = options.width || 1;this.height = options.height || 1;this.depth = options.depth || 1;this._modelMatrix = null;this._dirty = true;this.drawCommand = null;this.moveMaxHeight = 0;}// Model matrix getter with lazy computationget modelMatrix() {if (this._dirty) {const fixedFrameTransform = Cesium.Transforms.localFrameToFixedFrameGenerator('east', 'north');const mat4 = fixedFrameTransform(this.position);const scale = Cesium.Matrix4.fromScale(new Cesium.Cartesian3(this.width, this.width, this.depth));this._modelMatrix = Cesium.Matrix4.multiply(mat4, scale, new Cesium.Matrix4());this._dirty = false;}return this._modelMatrix;}// Method to generate positions, texture coordinates, and indicesgenerateGeometryData() {const positions = new Float64Array([0, 1, 0, -1, 0, 0, 0, -1, 0,  1, 0, 0, 0, 0, -1]);const indices = new Uint16Array([4, 2, 3, 4, 3, 0, 4, 0, 1, 4, 1, 2, 1, 2, 3, 1, 3, 0]);const textureCoordinates = new Float32Array([0, 0, 1, 0, 1, 1, 0, 1, 0.5, 0.5]);return {positions,indices,textureCoordinates};}// Method to create vertex arraycreateVertexArray(context) {const geometryData = this.generateGeometryData();const geometry = new Cesium.Geometry({attributes: {position: new Cesium.GeometryAttribute({componentDatatype: Cesium.ComponentDatatype.FLOAT,componentsPerAttribute: 3,values: geometryData.positions}),textureCoordinates: new Cesium.GeometryAttribute({componentDatatype: Cesium.ComponentDatatype.FLOAT,componentsPerAttribute: 2,values: geometryData.textureCoordinates})},indices: geometryData.indices,primitiveType: Cesium.PrimitiveType.TRIANGLES,boundingSphere: Cesium.BoundingSphere.fromVertices(geometryData.positions)});const geometryWithNormals = Cesium.GeometryPipeline.computeNormal(geometry);return Cesium.VertexArray.fromGeometry({context,geometry: geometryWithNormals,attributeLocations: {position: 0,textureCoordinates: 1},bufferUsage: Cesium.BufferUsage.STATIC_DRAW});}// Method to create a draw commandcreateDrawCommand(context) {const vertexArray = this.createVertexArray(context);const attributeLocations = {position: 0,textureCoordinates: 1};const shaderProgram = Cesium.ShaderProgram.fromCache({context,attributeLocations,vertexShaderSource: vs,fragmentShaderSource: fs,});const uniformMap = {color: () => Cesium.Color.GREEN,alpha: () => 1.0,moveMaxHeight: () => this.moveMaxHeight,};const renderState = Cesium.RenderState.fromCache({cull: {enabled: false,face: Cesium.CullFace.BACK},depthTest: {enabled: true}});this.drawCommand = new Cesium.DrawCommand({modelMatrix: this.modelMatrix,vertexArray,shaderProgram,renderState,uniformMap,pass: Cesium.Pass.OPAQUE});}// Update method to push the draw command into the frame stateupdate(frameState) {// Ensure the drawCommand is created if it hasn't been alreadyif (!this.drawCommand) {this.createDrawCommand(frameState.context);}// Add the draw command to the frame state for renderingframeState.commandList.push(this.drawCommand);}// Method to check if the primitive is destroyedisDestroyed() {return false;}
}

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

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

相关文章

PingCAP TiDB数据库专员PCTA认证笔记

tidb-pcta-note PingCAP TiDB数据库专员PCTA认证笔记 相关链接 官网认证中心 TiDB社区 体系架构 数据库设计 存算分离。三层架构:PD(Placement Driver)负责集群元信息管理和调度,TiDB负责sql计算,TiKV负责存储存…

建投数据与腾讯云数据库TDSQL完成产品兼容性互认证

近日,经与腾讯云联合测试,建投数据自主研发的人力资源信息管理系统V3.0、招聘管理系统V3.0、绩效管理系统V2.0、培训管理系统V3.0通过腾讯云数据库TDSQL的技术认证,符合腾讯企业标准的要求,产品兼容性良好,性能卓越。 …

电力通信规约-104实战

电力通信规约-104实战 概述 104规约在广泛应用于电力系统远动过程中,主要用来进行数据传输和转发,本文将结合实际开发实例来讲解104规约的真实使用情况。 实例讲解 因为个人技术栈是Java,所以本篇将采用Java实例来进行讲解。首先我们搭建一…

【3D打印机】启庞KP3S热床加热失败报错err6

最近天冷,打印机预热突然失败,热床无法加热,过了一段时间报错err6,查看另一篇资料说是天气冷原因,导致代码的PID控温部分达不到预期加热效果,从而自检报错,然后资料通过修改3D打印机代码的方式进…

SpiderFlow平台v0.5.0流程的执行过程

流程执行过程: 1. 流程启动 流程的执行通常从一个 开始节点 开始,该节点是整个爬虫任务的起点。开始节点没有实际的功能作用,主要作用是标记流程的起始。 执行顺序:在执行过程中,系统按照流程中的连接线顺序依次执行…

MySQL追梦旅途之慢查询分析建议

一、找到慢查询 查询是否开启慢查询记录 show variables like "%slow%";log_slow_admin_statements: 决定是否将慢管理语句(如 ALTER TABLE 等)记录到慢查询日志中。 log_slow_extra : MySQL 和 MariaDB 中的一个系…

Liveweb视频融合共享平台在果园农场等项目中的视频监控系统搭建方案

一、背景介绍 在我国的大江南北遍布着各种各样的果园,针对这些地处偏僻的果园及农场等环境,较为传统的安全防范方式是建立围墙,但是仅靠围墙仍然无法阻挡不法分子的有意入侵和破坏,因此为了及时发现和处理一些难以察觉的问题&…

Debezium日常分享系列之:Debezium 3.0.5.Final发布

Debezium日常分享系列之:Debezium 3.0.5.Final发布 重大变化Kafka信号源变更事件源信息块 新功能和改进核心允许在未知表上进行临时阻塞快照快照分发失败处理改进连接器启动配置日志改进 Postgres支持PostgreSQL 17的故障转移复制槽 Oracle跟踪部分回滚事件的新指标…

【Jenkins】持久化

文章目录 持续集成CI持续部署CD部署部署到linux服务器 持续集成好处: 持续集成CI 持续集成(Continuous integration,简称CI)指的是频繁地(一天多次)将代码集成到主干。 持续集成的目的就是让产品可以快速…

领域自适应

领域自适应(Domain Adaptation)是一种技术,用于将机器学习模型从一个数据分布(源域)迁移到另一个数据分布(目标域)。这在源数据和目标数据具有不同特征分布但任务相同的情况下特别有用。领域自适…

从零创建一个 Django 项目

1. 准备环境 在开始之前,确保你的开发环境满足以下要求: 安装了 Python (推荐 3.8 或更高版本)。安装 pip 包管理工具。如果要使用 MySQL 或 PostgreSQL,确保对应的数据库已安装。 创建虚拟环境 在项目目录中创建并激活虚拟环境&#xff…

【SH】在Ubuntu Server 24中基于Python Web应用的Flask Web开发(实现POST请求)学习笔记

文章目录 Flask开发环境搭建保持Flask运行Debug调试 路由和视图可变路由 请求和响应获取请求信息Request属性响应状态码常见状态码CookieSession 表单GET请求POST请求 Flask 在用户使用浏览器访问网页的过程中,浏览器首先会发送一个请求到服务器,服务器…

mybatis-plus配置找不到Mapper接口路径的坑

mybatis-plus今天遇到一个问题,就是mybatis 没有读取到mapper.xml 文件。 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.husy.mapper.SystemUserMapper.findUserByName at com.baomidou.mybatisplus.core.override.Myba…

Latex+VsCode+Win10搭建

最近在写论文,overleaf的免费使用次数受限,因此需要使用本地的形式进行编译。 安装TEXLive 下载地址:https://mirror-hk.koddos.net/CTAN/systems/texlive/Images/ 下载完成直接点击iso进行安装操作。 安装LATEX Workshop插件 设置VsCode文…

Linux世界中的指挥家:进程管理

文章一览 前言一、多道程序设计1.1 顺序程序活动的特点1.2 多道程序设计1.3 程序并发执行的特征 二、进程概念2.1 进程定义进程的根本属性: 2.2 进程的基本特征 三、进程状态3.1 进程的基本状态3.2 进程状态的转换3.3 进程族系 四、进程管理命令4.1 查看进程状态4.1…

LLMs之rStar:《Mutual Reasoning Makes Smaller LLMs Stronger Problem-Solvers》翻译与解读

LLMs之rStar:《Mutual Reasoning Makes Smaller LLMs Stronger Problem-Solvers》翻译与解读 导读:这篇论文提出了一种名为rStar的自我博弈互推理方法,用于增强小型语言模型 (SLMs) 的推理能力,无需微调或依赖更强大的模型。rStar…

软件测试面试题和简历模板(面试前准备篇)

一、问题预测 1、让简单介绍下自己(这个不用说了每次面试开场) 面试官,你好,我叫xxx,xx年本科毕业,从事软件测试将近3年的时间。在此期间做过一些项目也积累过一些经验,能够独立地完成软件测试…

BEVFormer论文总结

BEVFormer: Learning Bird’s-Eye-View Representation from Multi-Camera Images via Spatiotemporal Transformers BEVFormer:利用时空变换从多相机图像中学习鸟瞰表示 研究团队:南京大学、上海AI实验室、香港大学 ​ 代码地址:https://g…

Java爬虫获取1688 item_search_img接口详细解析

概述 1688作为中国领先的B2B电商平台,提供了丰富的API接口供开发者获取商品信息。item_search_img接口允许通过图片搜索商品,这对于需要基于图片进行商品查找的应用场景非常有用。本文将详细介绍如何使用Java爬虫技术获取1688的item_search_img接口数据…

eBPF试一下(TODO)

eBPF程序跟踪linux内核软中断 eBPF (Extended Berkeley Packet Filter) 是一种强大的 Linux 内核技术,最初用于网络数据包过滤,但现在它已经扩展到了多个领域,如性能监控、安全性、跟踪等。eBPF 允许用户在内核中执行代码(以一种安…