cesium模型压平
时间: 2023-07-05 19:24:22 浏览: 93
将Cesium模型压平可以通过以下步骤实现:
1. 在Cesium中加载模型,并将其转换为三角形网格,可以使用以下代码:
```javascript
var model = viewer.scene.primitives.add(Cesium.Model.fromGltf({
url : 'path/to/model.gltf'
}));
var geometry = model.getGeometryInstanceAttributes('box').vertexPositions;
var indices = model.getGeometryInstanceAttributes('box').indices;
var flattenedVertices = Cesium.Matrix4.multiplyByPoint(model.modelMatrix, geometry, new Array(geometry.length));
```
2. 对模型进行投影,可以使用以下代码:
```javascript
var projection = new Cesium.PolylineVolumeGeometry({
polylinePositions : Cesium.Cartesian3.fromDegreesArray([lon1, lat1, lon2, lat2]),
shapePositions : flattenedVertices
});
var flattenedProjection = projection.createGeometryInstance(normalizedDistance);
```
3. 创建新的模型实例,并将投影几何体添加到其中,可以使用以下代码:
```javascript
var flattenedModel = new Cesium.Model({
geometryInstances : flattenedProjection,
modelMatrix : Cesium.Transforms.eastNorthUpToFixedFrame(Cesium.Cartesian3.fromDegrees(lon, lat, height)),
id : 'flattened-model'
});
viewer.scene.primitives.add(flattenedModel);
```
这样就可以将Cesium模型压平并投影到地面上了。
阅读全文