GeometryAttribute

new Cesium.GeometryAttribute(options)

几何属性的值和类型信息。 Geometry 通常包含一个或多个属性。 所有属性一起形成 几何体的顶点。
Name Type Description
options object optional 对象,具有以下属性:
Name Type Default Description
componentDatatype ComponentDatatype 属性中每个组件的数据类型,例如,值中的单个元素。
componentsPerAttribute number 一个介于 1 和 4 之间的数字,用于定义属性中的组件数量。
normalize boolean false optionaltruecomponentDatatype 为整数格式时,指示当组件作为浮点访问以进行渲染时,应将组件映射到范围 [0, 1] (无符号) 或 [-1, 1] (有符号)。
values Array.<number> | Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array 存储在类型化数组中的属性的值。
Throws:
  • DeveloperError : options.componentsPerAttribute must be between 1 and 4.
Example:
const geometry = new Cesium.Geometry({
  attributes : {
    position : new Cesium.GeometryAttribute({
      componentDatatype : Cesium.ComponentDatatype.FLOAT,
      componentsPerAttribute : 3,
      values : new Float32Array([
        0.0, 0.0, 0.0,
        7500000.0, 0.0, 0.0,
        0.0, 7500000.0, 0.0
      ])
    })
  },
  primitiveType : Cesium.PrimitiveType.LINE_LOOP
});
See:

Members

属性中每个组件的数据类型,例如,其中的单个元素 GeometryAttribute#values.

componentsPerAttribute : number

一个介于 1 和 4 之间的数字,用于定义属性中的组件数。 例如,具有 x、y 和 z 分量的 position 属性将具有 3 作为 如代码示例所示。
Example:
attribute.componentDatatype = Cesium.ComponentDatatype.FLOAT;
attribute.componentsPerAttribute = 3;
attribute.values = new Float32Array([
  0.0, 0.0, 0.0,
  7500000.0, 0.0, 0.0,
  0.0, 7500000.0, 0.0
]);
truecomponentDatatype 为整数格式时, 表示组件应映射到范围 [0, 1](无符号) 或 [-1, 1](带符号)当它们作为浮点进行访问以进行渲染时。

这在使用 ComponentDatatype.UNSIGNED_BYTE 存储颜色时常用。

Default Value: false
Example:
attribute.componentDatatype = Cesium.ComponentDatatype.UNSIGNED_BYTE;
attribute.componentsPerAttribute = 4;
attribute.normalize = true;
attribute.values = new Uint8Array([
  Cesium.Color.floatToByte(color.red),
  Cesium.Color.floatToByte(color.green),
  Cesium.Color.floatToByte(color.blue),
  Cesium.Color.floatToByte(color.alpha)
]);

values : Array.<number>|Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array

存储在类型化数组中的属性的值。 在代码示例中, values 中的每 3 个元素定义一个属性,因为 componentsPerAttribute 为 3。
Example:
attribute.componentDatatype = Cesium.ComponentDatatype.FLOAT;
attribute.componentsPerAttribute = 3;
attribute.values = new Float32Array([
  0.0, 0.0, 0.0,
  7500000.0, 0.0, 0.0,
  0.0, 7500000.0, 0.0
]);
Need help? The fastest way to get answers is from the community and team on the Cesium Forum.