Cesium開發高級篇 | 01空間數據可視化之Primitive - 知乎
Primitive由兩部分組成:幾何體(Geometry)和外觀(Appearance)。幾何體定義了幾何類型、位置和顏色,例如三角形、多邊形、折線、點、標簽等;外觀則定義了Primitive的著色或渲染(Shading),包括GLSL(OpenGL著色語言,OpenGL Shading Language)頂點著色器和片元著色器( vertex and fragment shaders),以及渲染狀態(render state)。?粗略地說,幾何實例定義了結構和位置,外觀定義了視覺特征。
1.幾何類型
2.外觀
?
Cesium開發高級篇 | 02材質設置 - 知乎
Cesium中的Material類的內部機制是通過一種json格式的Fabric對象來表達物體的外觀特征,而這些外觀特征是由漫反射(diffuse)、鏡面反射(specular)、法向量(normal)、自發光(emission)以及透明度(alpha)組合(即一個Components)而成?。可通過兩種方式去獲取并設置幾何對象材質:
- Material.fromType方法
- Fabric方法
? // Create a color material with fromType: polygon.material = Cesium.Material.fromType('Color'); polygon.material.uniforms.color = new Cesium.Color(1.0, 1.0, 0.0, 1.0);----------------------------------------------------------------------------- // Create the default material: polygon.material = new Cesium.Material(); // Create a color material with full Fabric notation: polygon.material = new Cesium.Material({fabric : {type : 'Color',uniforms : {color : new Cesium.Color(1.0, 1.0, 0.0, 1.0)}} });?
兩種MaterialProperty
- ImageMaterialProperty 貼圖材質,可以給幾何對象表面貼上一張圖片。
var imgUrl = "./images/bumpmap.png";var imgMaterial = new Cesium.ImageMaterialProperty({image: imgUrl,repeat: new Cesium.Cartesian2(4, 4),color: Cesium.Color.BLUE,});viewer.entities.add({position: Cesium.Cartesian3.fromDegrees(-65.0, 40.0, 100000.0),ellipse: {semiMajorAxis: 300000.0, // 長半軸距離semiMinorAxis: 200000.0, // 短半軸距離height: 20000.0,material: imgMaterial,},});
- PolylineArrowMaterialProperty 帶有箭頭的線
官方案例Cesium Sandcastle
3.常見方法
getGeometryInstanceAttributes(id)
Returns the modifiable per-instance attributes for a?GeometryInstance.
返回一個GeometryInstance的可修改的每個實例屬性。
const attributes = primitive.getGeometryInstanceAttributes('an id'); attributes.color = Cesium.ColorGeometryInstanceAttribute.toValue(Cesium.Color.AQUA); attributes.show = Cesium.ShowGeometryInstanceAttribute.toValue(true); attributes.distanceDisplayCondition = Cesium.DistanceDisplayConditionGeometryInstanceAttribute.toValue(100.0, 10000.0); attributes.offset = Cesium.OffsetGeometryInstanceAttribute.toValue(Cartesian3.IDENTITY);
4.貼地或貼模型特性
Cesium Sandcastle?線貼模型
Cesium Sandcastle
Cesium貼地設置_primitive貼地-CSDN博客
跟Entity[HeightReference]類似,Primitive也支持貼地或貼模型的特性,但不一樣的是,Primitive是通過classificationType屬性控制的。其中GroundPolylineGeometry、GroundPolylinePrimitive結合實現貼地線;
GroundPrimitive實現貼地幾何形狀,包括CircleGeometry、CorridorGeometry、EllipseGeometry、PolygonGeometry、RectangleGeometry;ClassificationPrimitive可實現貼地或貼模型,包括BoxGeometry、CylinderGeometry、EllipsoidGeometry、PolylineVolumeGeometry、SphereGeometry幾何形狀。
5.GroupPrimitive
GroupPrimitive表示場景中覆蓋在Terrain或3DTiles上的幾何體
- ?Support for the WEBGL_depth_texture extension is required to use GeometryInstances with different PerInstanceColors or materials besides PerInstanceColorAppearance.
(支持WEBGL_depth_texture擴展需要使用不同的PerInstanceColors或PerInstanceColor Appearance?材料的GeometryInstances。)
- Textured GroundPrimitives were designed for notional patterns and are not meant for precisely mapping textures to terrain - for that use case, use?SingleTileImageryProvider
Textured GroundPrimitives是為空想模式設計的,并不是為了精確地將紋理映射到地形。對于這種情況,使用SingleTileImageryProvider。
- 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.
為了正確渲染,這個特性需要EXT_frag_depth WebGL擴展。對于不支持此擴展的硬件,將會有一些視角的渲染工件。
- Valid geometries are?CircleGeometry,?CorridorGeometry,?EllipseGeometry,?PolygonGeometry, and?RectangleGeometry.
常見方法 :
Cesium.GroundPrimitive.initializeTerrainHeights()?
- Initializes the minimum and maximum terrain heights. This only needs to be called if you are creating the GroundPrimitive synchronously.
- Return:A promise that will resolve once the terrain heights have been loaded.
Cesium.GroundPrimitive.isSupported(scene)
Cesium.GroundPrimitive.supportsMaterials(scene)
- Checks if the given Scene supports materials on GroundPrimitives. Materials on GroundPrimitives require support for the WEBGL_depth_texture extension.
- Return:Checks if the given Scene supports materials on GroundPrimitives. Materials on GroundPrimitives require support for the WEBGL_depth_texture extension.
getGeometryInstanceAttributes(id)
6.PrimtiveCollection
常見方法:
7.Property