cesium drawcommand获取
时间: 2023-07-05 07:18:11 浏览: 173
要使用Cesium的DrawCommand对象,可以按照以下步骤进行操作:
1. 首先,创建一个Cesium的Viewer对象,将其挂载到DOM元素上。
```javascript
var viewer = new Cesium.Viewer('cesiumContainer');
```
2. 接着,创建一个Primitive对象,用于存储要绘制的几何图形的信息。
```javascript
var primitive = new Cesium.Primitive({
geometryInstances: new Cesium.GeometryInstance({
geometry: new Cesium.BoxGeometry({
dimensions: new Cesium.Cartesian3(400000.0, 300000.0, 500000.0)
}),
modelMatrix: Cesium.Matrix4.multiplyByTranslation(
Cesium.Transforms.eastNorthUpToFixedFrame(Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883)),
new Cesium.Cartesian3(0.0, 0.0, 500000.0),
new Cesium.Matrix4()
),
attributes: {
color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.RED.withAlpha(0.5))
}
}),
appearance: new Cesium.PerInstanceColorAppearance({
flat: true,
translucent: false
}),
asynchronous: false
});
```
3. 创建一个DrawCommand对象,用于指定绘制命令的参数,例如模型矩阵、渲染状态等。
```javascript
var drawCommand = new Cesium.DrawCommand({
primitiveType: Cesium.PrimitiveType.TRIANGLES,
vertexArray: primitive.getGeometryInstanceAttributes().vertexArray,
modelMatrix: primitive.getGeometryInstanceAttributes().modelMatrix,
pickId: 1,
boundingVolume: primitive.getBoundingSphere(new Cesium.BoundingSphere()),
shaderProgram: Cesium.ShaderProgram.fromCache({
context: viewer.scene.context,
vertexShaderSource: '',
fragmentShaderSource: ''
}),
framebuffer: viewer.scene.frameState.framebuffer,
renderState: viewer.scene.frameState.renderState,
pass: Cesium.Pass.OPAQUE
});
```
4. 最后,可以通过调用Viewer对象的render函数,将绘制命令传递给WebGL渲染器,进行绘制。
```javascript
viewer.render();
```
阅读全文