Geometry

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 完全包围该几何体的可选包围球。
Example:
// Create geometry with a position attribute and indexed lines.
const positions = new Float64Array([
  0.0, 0.0, 0.0,
  7500000.0, 0.0, 0.0,
  0.0, 7500000.0, 0.0
]);

const 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:
See:

Members

构成几何体顶点的属性。该对象中的每个属性都对应一个 GeometryAttribute,其中包含该属性的数据。

在 Geometry 中,属性始终以非交错(non-interleaved)方式存储。

有一些具有已知语义的保留属性名。以下属性 由 Geometry 创建(取决于所提供的 VertexFormat

  • position - 3D 顶点位置。64 位浮点数(用于精度)。每个属性 3 个分量。参见 VertexFormat#position
  • normal - 法线(已归一化),通常用于光照。32 位浮点数。每个属性 3 个分量。参见 VertexFormat#normal
  • st - 2D 纹理坐标。32 位浮点数。每个属性 2 个分量。参见 VertexFormat#st
  • bitangent - 副切线(已归一化),用于法线贴图等切空间效果。32 位浮点数。每个属性 3 个分量。参见 VertexFormat#bitangent
  • tangent - 切线(已归一化),用于法线贴图等切空间效果。32 位浮点数。每个属性 3 个分量。参见 VertexFormat#tangent

The following attribute names are generally not created by a Geometry, but are added to a Geometry by a Primitive or GeometryPipeline functions to prepare the geometry for rendering.

  • position3DHigh - High 32 bits for encoded 64-bit position computed with GeometryPipeline.encodeAttribute. 32-bit floating-point. 4 components per attribute.
  • position3DLow - Low 32 bits for encoded 64-bit position computed with GeometryPipeline.encodeAttribute. 32-bit floating-point. 4 components per attribute.
  • position2DHigh - High 32 bits for encoded 64-bit 2D (Columbus view) position computed with GeometryPipeline.encodeAttribute. 32-bit floating-point. 4 components per attribute.
  • position2DLow - Low 32 bits for encoded 64-bit 2D (Columbus view) position computed with GeometryPipeline.encodeAttribute. 32-bit floating-point. 4 components per attribute.
  • color - RGBA color (normalized) usually from GeometryInstance#color. 32-bit floating-point. 4 components per attribute.
  • pickColor - RGBA color used for picking. 32-bit floating-point. 4 components per attribute.

Example:
geometry.attributes.position = new Cesium.GeometryAttribute({
  componentDatatype : Cesium.ComponentDatatype.FLOAT,
  componentsPerAttribute : 3,
  values : new Float32Array(0)
});
See:
完全包围几何体的可选包围球。这 通常用于剔除(culling)。
Default Value: undefined

indices : Array|undefined

Geometry#primitiveType 一起 确定几何体中图元的可选索引数据。
Default Value: undefined
几何体中图元的类型。它最常见的是 PrimitiveType.TRIANGLES, 但也可能根据具体几何体的不同而不同。
Default Value: PrimitiveType.TRIANGLES

Methods

static Cesium.Geometry.computeNumberOfVertices(geometry)number

计算几何体中的顶点数量。其运行时间与顶点中 属性的数量呈线性关系,而非与顶点数量相关。
Name Type Description
geometry Geometry 几何体。
Returns:
几何体中的顶点数量。
Example:
const numVertices = Cesium.Geometry.computeNumberOfVertices(geometry);
需要帮助?获取答案的最快方式是在 Cesium 论坛 上向社区和团队提问。