Cesium自定义Primitive
一般情况下我们使用实体类时,会直接用Entity,但是动态更新实时渲染的不闪烁的话,得使用CallbackProperty回调函数,比较麻烦。可以通过自定义Primitive达到实时渲染效果。
function CustomPolygonPrimtive (options) {this.positions = options.positionsthis.color = options.colorthis._positions = undefinedthis._color = new Cesium.Color(1, 0, 0, 1)
}CustomPolygonPrimtive.prototype.getGeometry = function () {return new Cesium.PolygonGeometry({polygonHierarchy: new Cesium.PolygonHierarchy(this.positions),perPositionHeight: true,vertexFormat: Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT})
}CustomPolygonPrimtive.prototype.getPrimitive = function () {var geometry = this.getGeometry()var instances = new Cesium.GeometryInstance({geometry: geometry })return new Primitive({geometryInstances: instances,appearance: new Cesium.EllipsoidSurfaceAppearance({material: Cesium.Material.fromType('Color', {color: this.color}),renderState: {depthTest: {enabled: false}}}),asynchronous: false})
}CustomPolygonPrimtive.prototype.update = function (context, frameState, commandList) {if (!(this.positions !== this._positions || this.color !== this._color)) {if (this._primitive) {this._primitive.update(context, frameState, commandList)}return;}this._positions = this.position;this._color = this.color;this._primitive = this._primitive && this._primitive.destroy()this._primitive = this.getPrimitive()if (!this._primitive) return;this._primitive.update(context, frameState, commandList)
}CustomPolygonPrimtive.prototype.isDestroyed = function () {return false}CustomPolygonPrimtive.prototype.destroy = function () {this._primitive = this._primitive && this._primitive.destroy()return Cesium.destroyObject(this)}//如何使用
viewer.scene.primitives.add(new CustomPolygonPrimtive(options))
上面代码演示的是自定义Polygon面的实现,只加了坐标positions和颜色color,修改实例化后的CustomPolygonPrimtive两个参数时会实时渲染,不会出现闪烁。上面的代码没做详细的判断,比如positions数组加点或者减少时的判断,数组是引用类型,所以不会变,有需要的可以自己在上面基础上更改代码。
Cesium自定义Primitive相关推荐
- Cesium使用DrawCommand自定义Primitive初体验
1.创建DrawCommand // vertexArray :顶点数组,向 GPU 传递顶点属性.索引(可选的)数组等几何信息: // shaderProgram :着色器程序对象,负责编译.链接顶 ...
- Cesium 自定义箭头坐标轴 圆坐标轴(一)
Cesium 自定义箭头坐标轴 圆坐标轴(一) 箭头坐标轴和圆坐标轴 实现思路 绘制箭头坐标 绘制圆坐标 总结 箭头坐标轴和圆坐标轴 为了实现Cesium 对模型的拖拽平移和旋转,需要以模型为中心建立 ...
- cesium采用primitive方式加载geojson数据
cesium采用primitive方式加载geojson数据 cesium加载geojson数据有自带的接口GeoJsonDataSource和演示 示例,使用的是entity方式来加载数据,而ent ...
- Cesium自定义天空盒子图片
Cesium自定义天空盒子图片 效果图 改造SkyBox代码 const {BoxGeometry,Cartesian3,defaultValue,defined,destroyObject,Deve ...
- Cesium自定义天空盒
Cesium自定义天空盒 前言 Cesium自带有天空盒满足大多数场景,但是在一下特殊场景可能自带的天空盒不太适用. 实现效果 实现思路 Cesium远景天空盒可以使用Cesium.SkyBox类实现 ...
- Cesium中Primitive与Entity详细介绍
文章目录 1.概述 2.Primitive 2.1Geometry 2.2Appearance 2.3优势与不足 3.Entity Cesium实战系列文章总目录: 传送门 1.概述 Cesium为开 ...
- Cesium 通过primitive 添加垂直图片资源
实际Cesium 项目中添加了部分贴地的资源.资源类型有图片,gltf或者glb的模型.这里简单比较一下primitive 和entity. primitive 基于比较底层的webgl技术,进行渲染 ...
- Cesium自定义shader材质实现逼真水面,支持uniforms属性实时修改
水的shader代码参考的是Shader - Shadertoy BETA 本文主要解决在cesium的shader中如何实时修改时间变量iTime,从而实现材质的动态变化. MaterialAppe ...
- Cesium自定义编辑多边形
参考geojson.io网站用cesium实现自定义编辑多边形功能 绘制多边形 在cesium官方所给的实例中,Drawing on Terrain中可以做到自定义绘制多边形,但无法做到修改编辑,因此 ...
最新文章
- JDK 16 GA 发布,你还停留在JDK 8吗?
- python编译成exe速度会变快吗_python如何编译成exe
- iOS 滚动图滚动到顶部汇总
- Python:用生成器的方式计算任意起止范围内质数的和。
- PostgreSQL 分库分表 插件之一 pg_shard
- ubuntu16.0.4安装mysql5.7以及设置远程访问
- C 标准库 —— scanf(fflush(stdin))
- [wcf]入门.3.1
- 亲身经历:2018年深圳保洁员工资时薪75,月薪不清楚
- 卸载Symantec——无需密码,卸载干净,Windows
- Carrot2 - Wikipedia, the free encyclopedia
- 树莓派4B引脚定义及运行实例
- 微型计算机启天m425显卡驱动,联想启天M425安装win7系统详细教程包括BIOS设置方法USB驱动...
- 在WIN10中安装经典计算器
- Sklearn提供的常用数据集
- 【vue】pdf转图片
- jQuery插件实现瀑布流
- 佛祖保佑 永无shell
- pandas 筛选数据的 8 个骚操作
- Ubuntu Windows双系统切换最简方法!!!