GeometryPipeline

用于几何体的内容管线(pipeline)函数。
See:

Methods

static Cesium.GeometryPipeline.compressVertices(geometry)Geometry

压缩并打包几何体法线属性值以节省内存。
Name Type Description
geometry Geometry 要修改的几何体。
Returns:
修改后的 geometry 参数,其法线已被压缩并打包。
Example:
geometry = Cesium.GeometryPipeline.compressVertices(geometry);

static Cesium.GeometryPipeline.computeNormal(geometry)Geometry

通过计算与顶点相关的 所有三角形的法线平均值,为包含 TRIANGLES 的几何体计算逐顶点法线。结果是一个新的 normal 属性被添加到几何体中。 这假设采用逆时针(counter-clockwise)环绕顺序。
Name Type Description
geometry Geometry 要修改的几何体。
Returns:
修改后的 geometry 参数,带有计算出的 normal 属性。
Throws:
Example:
Cesium.GeometryPipeline.computeNormal(geometry);

static Cesium.GeometryPipeline.computeTangentAndBitangent(geometry)Geometry

为包含 TRIANGLES 的几何体计算逐顶点切线和副切线。 结果是将新的 tangentbitangent 属性添加到几何体中。 这假设采用逆时针环绕顺序。

基于 Eric Lengyel 的 Computing Tangent Space Basis Vectors for an Arbitrary Mesh

Name Type Description
geometry Geometry 要修改的几何体。
Returns:
修改后的 geometry 参数,带有计算出的 tangentbitangent 属性。
Throws:
Example:
Cesium.GeometryPipeline.computeTangentAndBiTangent(geometry);

static Cesium.GeometryPipeline.createAttributeLocations(geometry)object

创建一个对象,将属性名称映射到唯一的位置(索引), 以匹配顶点属性和着色器程序。
Name Type Description
geometry Geometry 用于创建该对象的几何体(不会被修改)。
Returns:
一个包含属性名称/索引对的对象。
Example:
const attributeLocations = Cesium.GeometryPipeline.createAttributeLocations(geometry);
// Example output
// {
//   'position' : 0,
//   'normal' : 1
// }

static Cesium.GeometryPipeline.createLineSegmentsForVectors(geometry, attributeName, length)Geometry

创建一个带有 LINES 的新 Geometry,表示所提供几何体 的给定属性(attributeName)。这用于 可视化法线、切线和副切线等向量属性。
Name Type Default Description
geometry Geometry 带有该属性的 Geometry 实例。
attributeName string 'normal' optional 属性的名称。
length number 10000.0 optional 每条线段的长度,单位为米。可以为负值,以使向量指向相反方向。
Returns:
一个新的 Geometry 实例,带有表示该向量的线段。
Throws:
  • DeveloperError : geometry.attributes 必须包含一个与 attributeName 参数同名的属性。
Example:
const geometry = Cesium.GeometryPipeline.createLineSegmentsForVectors(instance.geometry, 'bitangent', 100000.0);

static Cesium.GeometryPipeline.encodeAttribute(geometry, attributeName, attributeHighName, attributeLowName)Geometry

将浮点几何体属性值编码为两个独立的属性,以提高 渲染精度。

这通常用于创建高精度的位置顶点属性。

Name Type Description
geometry Geometry 要修改的几何体。
attributeName string 属性的名称。
attributeHighName string 编码高位属性的名称。
attributeLowName string 编码低位属性的名称。
Returns:
修改后的 geometry 参数,带有其编码后的属性。
Throws:
  • DeveloperError : geometry 必须包含与 attributeName 参数匹配的属性。
  • DeveloperError : 该属性的 componentDatatype 必须为 ComponentDatatype.DOUBLE。
Example:
geometry = Cesium.GeometryPipeline.encodeAttribute(geometry, 'position3D', 'position3DHigh', 'position3DLow');

static Cesium.GeometryPipeline.fitToUnsignedShortIndices(geometry)Array.<Geometry>

如有必要,将几何体拆分为多个几何体,以确保 indices 能放入无符号短整型(unsigned short)中。这用于在不支持无符号整型索引时 满足 WebGL 的要求。

如果几何体没有任何 indices,此函数没有效果。

Name Type Description
geometry Geometry 要拆分为多个几何体的几何体。
Returns:
一组几何体,每个的索引都能放入无符号短整型中。
Throws:
  • DeveloperError : geometry.primitiveType 必须等于 PrimitiveType.TRIANGLES、PrimitiveType.LINES 或 PrimitiveType.POINTS。
  • DeveloperError : 所有几何体属性列表必须具有相同数量的属性。
Example:
const geometries = Cesium.GeometryPipeline.fitToUnsignedShortIndices(geometry);

static Cesium.GeometryPipeline.projectTo2D(geometry, attributeName, attributeName3D, attributeName2D, projection)Geometry

将几何体的三维 position 属性投影到二维,用独立的 position3Dposition2D 属性替换 position 属性。

如果几何体没有 position,此函数没有效果。

Name Type Default Description
geometry Geometry 要修改的几何体。
attributeName string 属性的名称。
attributeName3D string 三维属性的名称。
attributeName2D string 二维属性的名称。
projection object new GeographicProjection() optional 要使用的投影。
Returns:
修改后的 geometry 参数,带有 position3Dposition2D 属性。
Throws:
  • DeveloperError : geometry 必须包含与 attributeName 参数匹配的属性。
  • DeveloperError : 该属性的 componentDatatype 必须为 ComponentDatatype.DOUBLE。
  • DeveloperError : 无法将点投影到二维。
Example:
geometry = Cesium.GeometryPipeline.projectTo2D(geometry, 'position', 'position3D', 'position2D');

static Cesium.GeometryPipeline.reorderForPostVertexCache(geometry, cacheCapacity)Geometry

使用 Tipsify 算法重新排序几何体的 indices,以通过 GPU 的 顶点着色器后缓存(post vertex-shader cache)获得更好的性能。如果几何体的 primitiveType 不是 TRIANGLES,或者几何体没有 indices,此函数没有效果。
Name Type Default Description
geometry Geometry 要修改的几何体。
cacheCapacity number 24 optional GPU 顶点缓存中可以容纳的顶点数量。
Returns:
修改后的 geometry 参数,其索引已为顶点着色器后缓存重新排序。
Throws:
Example:
geometry = Cesium.GeometryPipeline.reorderForPostVertexCache(geometry);
See:

static Cesium.GeometryPipeline.reorderForPreVertexCache(geometry)Geometry

重新排序几何体的属性和 indices,以通过 GPU 的顶点着色器前缓存(pre-vertex-shader cache)获得更好的性能。
Name Type Description
geometry Geometry 要修改的几何体。
Returns:
修改后的 geometry 参数,其属性和索引已为 GPU 的顶点着色器前缓存重新排序。
Throws:
  • DeveloperError : geometry.attributes 中的每个属性数组必须具有相同数量的属性。
Example:
geometry = Cesium.GeometryPipeline.reorderForPreVertexCache(geometry);
See:

static Cesium.GeometryPipeline.toWireframe(geometry)Geometry

将几何体的三角形索引转换为线段索引。如果几何体具有 indicesprimitiveTypeTRIANGLESTRIANGLE_STRIPTRIANGLE_FAN,则将其转换为 LINES;否则,几何体不会被更改。

这通常用于为可视化调试创建线框几何体。

Name Type Description
geometry Geometry 要修改的几何体。
Returns:
修改后的 geometry 参数,其三角形索引已转换为线段。
Throws:
  • DeveloperError : geometry.primitiveType 必须为 TRIANGLES、TRIANGLE_STRIP 或 TRIANGLE_FAN。
Example:
geometry = Cesium.GeometryPipeline.toWireframe(geometry);

static Cesium.GeometryPipeline.transformToWorldCoordinates(instance)GeometryInstance

将几何实例变换到世界坐标系。这会 将该实例的 modelMatrix 更改为 Matrix4.IDENTITY,并变换以下属性(如果存在):positionnormaltangentbitangent
Name Type Description
instance GeometryInstance 要修改的几何实例。
Returns:
修改后的 instance 参数,其属性已变换到世界坐标系。
Example:
Cesium.GeometryPipeline.transformToWorldCoordinates(instance);
需要帮助?获取答案的最快方式是在 Cesium 论坛 上向社区和团队提问。