麻辣GIS微信平台

更多 GIS 干货

微信关注不错过

Cesium API - Geometry 中文文档

本文介绍下Cesium中 Geometry API的详细使用说明。

Geometry API 调用方法

new Cesium.Geometry(options)
几何图形表示为具有组织顶点的属性和定义图元的可选索引数据。 几何图形和描述着色的Appearance可以分配给Primitive进行可视化。 Primitive可以由许多不同的几何图形(在许多情况下)创建,以提高性能。

可以使用GeometryPipeline中的函数对几何图形进行转换和优化。

Name Type Description
options Object 对象,具有以下属性:
Name Type Default Description
attributes GeometryAttributes 组成几何图形的顶点的属性。
primitiveType PrimitiveType PrimitiveType.TRIANGLES optional 几何图形中的图元类型。
indices Uint16Array | Uint32Array optional 可选索引数据,用于确定几何图形中的图元。
boundingSphere BoundingSphere optional 一个可选的包围球,完全包围了几何图形。
示例:
// 使用位置属性和线索引创建几何图形。
var positions = new Float64Array([
  0.0, 0.0, 0.0,
  7500000.0, 0.0, 0.0,
  0.0, 7500000.0, 0.0
]);
var geometry = new Cesium.Geometry({
  attributes : {
    position : new Cesium.GeometryAttribute({
      componentDatatype : Cesium.ComponentDatatype.DOUBLE,
      componentsPerAttribute : 3,
      values : positions
    })
  },
  indices : new Uint16Array([0, 1, 1, 2, 2, 0]),
  primitiveType : Cesium.PrimitiveType.LINES,
  boundingSphere : Cesium.BoundingSphere.fromVertices(positions)
});
演示Demo:
参考:

成员变量

组成几何图形的顶点的属性。这个对象中的每个属性都对应一个GeometryAttribute,其中包含属性的数据。

属性总是以非交插(non-interleaved)的方式存储在几何图形中。

保留具有众所周知语义的属性名称。以下属性由Geometry(取决于提供的VertexFormat)创建。

  • position - 3D顶点位置。64位浮点数(用于精度)。 每个属性3个分量。请参见 VertexFormat#position
  • normal - 标准(标准化的), 通常用于光照。32位浮点数。每个属性3个分量。请参见 VertexFormat#normal
  • st - 2D纹理坐标。32位浮点数。每个属性2个分量。请参见VertexFormat#st.
  • bitangent - Bitangent(标准化的),用于切线空间(tangent-space)效果,如凹凸贴图(bump mapping)。32位浮点数。每个属性3个分量。请参见 VertexFormat#bitangent
  • tangent - Tangent(标准化的),用于切线空间(tangent-space)效果,如凹凸贴图(bump mapping)。32位浮点数。每个属性3个分量。请参见 VertexFormat#tangent

以下属性名通常不是由Geometry创建的,而是由PrimitiveGeometryPipeline函数添加到Geometry中,以便为渲染几何图形做好准备。

  • position3DHigh - 使用GeometryPipeline.encodeAttribute计算得出的已编码64位位置的高32位。32位浮点数。每个属性4个分量。
  • position3DLow - 使用GeometryPipeline.encodeAttribute计算得出的已编码64位位置的低32位。32位浮点数。每个属性4个分量。
  • position2DHigh - 使用GeometryPipeline.encodeAttribute计算得出的已编码的64位2D(Columbus view)位置的高32位。 32位浮点数。每个属性4个分量。
  • position2DLow - 使用GeometryPipeline.encodeAttribute计算得出的已编码的64位2D(Columbus view)位置的低32位。 32位浮点数。每个属性4个分量。
  • color - 通常从GeometryInstance#color而来的RGBA颜色(标准化)。32位浮点数。每个属性4个分量。
  • pickColor - 用于拾取的RGBA颜色。32位浮点数。每个属性4个分量。

Default Value: undefined
示例:
geometry.attributes.position = new Cesium.GeometryAttribute({
  componentDatatype : Cesium.ComponentDatatype.FLOAT,
  componentsPerAttribute : 3,
  values : new Float32Array(0)
});
参考:
一个可选的包围球,完全包围几何图形。这是通常用于筛选(culling)。
Default Value: undefined
indices : Array
可选的索引数据——与Geometry#primitiveType一起——决定几何图形中的图元。
Default Value: undefined
几何图形中的图元类型。这通常是PrimitiveType.TRIANGLES,但可以根据具体的几何形状变化。
Default Value: undefined

内置方法

staticCesium.Geometry.computeNumberOfVertices(geometry)Number
计算几何图形中的顶点数。运行时与顶点的属性数量有关,而与顶点的数量无关。
Name Type Description
geometry Geometry 几何图形。
返回值:
几何图形中的顶点数。
示例:
var numVertices = Cesium.Geometry.computeNumberOfVertices(geometry);

其他API

Cesium中文API文档手册(v1.63.1版本)参考:《Cesium中文API文档手册(v1.63.1版本)

相关阅读

麻辣GIS-Sailor

作者:

GIS爱好者,学GIS,更爱玩GIS。

声明

1.本文所分享的所有需要用户下载使用的内容(包括但不限于软件、数据、图片)来自于网络或者麻辣GIS粉丝自行分享,版权归该下载资源的合法拥有者所有,如有侵权请第一时间联系本站删除。

2.下载内容仅限个人学习使用,请切勿用作商用等其他用途,否则后果自负。

手机阅读
公众号关注
知识星球
手机阅读
麻辣GIS微信公众号关注
最新GIS干货
关注麻辣GIS知识星球
私享圈子

留言板(小编看到第一时间回复)