1. 程式人生 > 其它 >Cesium 使用primitive繪製幾何圖形,相機拉近(視野放大),幾何圖形破損顯示不完整

Cesium 使用primitive繪製幾何圖形,相機拉近(視野放大),幾何圖形破損顯示不完整

分析:此原因是因為地形導致,可以嘗試將primitive設定高程(高度)如5000m,此時圖形位置由於高於山峰等地形,圖形可以顯示完整。

但是如果幾何圖形必須要貼地(高度為0m)呢?

解決方法:

1.設定scene.globe.depthTestAgainstTerrain = false;即不進行地形深度測試,也就忽略了地形。這時可以正常顯示幾何圖形。

2.使用GroundPrimitive。顧名思義,這是幫助你將幾何圖形貼地的類。

scene.primitives.add(new Cesium.GroundPrimitive({

		geometryInstances : instances,
		appearance : new Cesium.PerInstanceColorAppearance()
	}));

這裡給出官方的解釋:

A ground primitive represents geometry draped over the terrain in the Scene. The geometry must be from a single GeometryInstance. Batching multiple geometries is not yet supported.

A primitive combines the geometry instance with an Appearance that describes the full shading, including Material

and RenderState. Roughly, the geometry instance defines the structure and placement, and the appearance defines the visual characteristics. Decoupling geometry and appearance allows us to mix and match most of them and add a new geometry or appearance independently of each other. Only the PerInstanceColorAppearance
is supported at this time.

For correct rendering, this feature requires the EXT_frag_depth WebGL extension. For hardware that do not support this extension, there will be rendering artifacts for some viewing angles.

Valid geometries are CircleGeometry, CorridorGeometry, EllipseGeometry, PolygonGeometry, and RectangleGeometry.

這裡給出官方demo:

var rectangleInstance = new Cesium.GeometryInstance({   geometry : new Cesium.RectangleGeometry({     rectangle : Cesium.Rectangle.fromDegrees(-140.0, 30.0, -100.0, 40.0)   }),   id : 'rectangle',   attributes : {     color : new Cesium.ColorGeometryInstanceAttribute(0.0, 1.0, 1.0, 0.5)   } }); scene.primitives.add(new Cesium.GroundPrimitive({   geometryInstances : rectangleInstance }));

本文轉自 https://blog.csdn.net/u013821237/article/details/80221108,如有侵權,請聯絡刪除。