Cesium动态绘制面,线,点

本文介绍了一种能够根据用户需求自动调整宽度和颜色的动态绘制点、线、面的方法,并提供了实现这一功能的代码链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

因为客户需求,最近需要写一个动态绘制面和点,线,还能删除 面,点,线entity对象的方式

先上效果图

 

 可以根据用户自动选择 宽度 ,颜色可以自动设置点线面的颜色粗细

实现代码已经上传连接

要使用Cesium绘制,您需要使用Cesium.Primitive类型。以下是一个简单的示例,演示了如何使用Cesium.Primitive绘制一个三角形: ```javascript //创建顶数组 var positions = [ 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0 ]; //创建颜色数组 var colors = [ 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0 ]; //创建索引数组 var indices = [0, 1, 2]; //创建几何体 var geometry = new Cesium.Geometry({ attributes: { position: new Cesium.GeometryAttribute({ componentDatatype: Cesium.ComponentDatatype.DOUBLE, componentsPerAttribute: 3, values: positions }), color: new Cesium.GeometryAttribute({ componentDatatype: Cesium.ComponentDatatype.FLOAT, componentsPerAttribute: 4, values: colors }) }, indices: indices, primitiveType: Cesium.PrimitiveType.TRIANGLES }); //创建材质 var material = new Cesium.Material({ fabric: { type: 'Color', uniforms: { color: new Cesium.Color(1.0, 1.0, 1.0, 1.0) } } }); //创建渲染参数 var renderState = Cesium.RenderState.fromCache({ depthTest: { enabled: true }, depthMask: true, blending: Cesium.BlendingState.ALPHA_BLEND }); //创建几何体实例 var primitive = new Cesium.Primitive({ geometryInstances: new Cesium.GeometryInstance({ geometry: geometry, modelMatrix: Cesium.Matrix4.IDENTITY, attributes: { color: colors }, id: 'triangle' }), appearance: new Cesium.PerInstanceColorAppearance({ flat: true }), material: material, renderState: renderState }); //将几何体添加到场景中 viewer.scene.primitives.add(primitive); ``` 在上的示例中,我们创建了一个三角形的顶、颜色和索引数组。然后,我们使用这些数组创建了一个Cesium.Geometry实例。接下来,我们创建了一个Cesium.Material实例和一个渲染参数Cesium.RenderState实例。最后,我们将Cesium.Geometry实例和Cesium.Material实例一起传递给Cesium.Primitive构造函数,并将其添加到场景中。 注意,上的示例仅绘制了一个三角形,如果您需要绘制更复杂的几何体,您需要创建更复杂的顶和索引数组。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小白学过的代码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值