GeometryPipeline
Content pipeline functions for geometries.
Methods
-
<static> combine
-
Combines geometry from several GeometryInstance objects into one geometry. This concatenates the attributes, concatenates and adjusts the indices, and creates a bounding sphere encompassing all instances.
If the instances do not have the same attributes, a subset of attributes common to all instances is used, and the others are ignored.
This is used by Primitive to efficiently render a large amount of static data.
Parameters:
Name Type Argument Description instances
Array <optional>
The array of GeometryInstance objects whose geometry will be combined. Throws:
-
DeveloperError : instances is required and must have length greater than zero.
-
DeveloperError : All instances must have the same modelMatrix.
-
DeveloperError : All instance geometries must have an indices or not have one.
-
DeveloperError : All instance geometries must have the same primitiveType.
Returns:
Geometry A single geometry created from the provided geometry instances.Example
for (var i = 0; i < instances.length; ++i) { GeometryPipeline.transformToWorldCoordinates(instances[i]); } var geometry = GeometryPipeline.combine(instances);
-
-
<static> computeBinormalAndTangent
-
Computes per-vertex binormals and tangents for a geometry containing
TRIANGLES
. The result is newbinormal
andtangent
attributes added to the geometry. This assumes a counter-clockwise winding order.Based on Computing Tangent Space Basis Vectors for an Arbitrary Mesh by Eric Lengyel.
Parameters:
Name Type Description geometry
Geometry The geometry to modify. Throws:
-
DeveloperError : geometry is required.
-
DeveloperError : geometry.attributes.position.values is required.
-
DeveloperError : geometry.attributes.normal.values is required.
-
DeveloperError : geometry.attributes.st.values is required.
-
DeveloperError : geometry.indices is required.
-
DeveloperError : geometry.indices length must be greater than 0 and be a multiple of 3.
-
DeveloperError : geometry.primitiveType must be PrimitiveType.TRIANGLES.
Returns:
Example
GeometryPipeline.computeBinormalAndTangent(geometry);
-
-
<static> computeNormal
-
Computes per-vertex normals for a geometry containing
TRIANGLES
by averaging the normals of all triangles incident to the vertex. The result is a newnormal
attribute added to the geometry. This assumes a counter-clockwise winding order.Parameters:
Name Type Description geometry
Geometry The geometry to modify. Throws:
-
DeveloperError : geometry is required.
-
DeveloperError : geometry.attributes.position.values is required.
-
DeveloperError : geometry.indices is required.
-
DeveloperError : geometry.indices length must be greater than 0 and be a multiple of 3.
-
DeveloperError : geometry.primitiveType must be PrimitiveType.TRIANGLES.
Returns:
Example
GeometryPipeline.computeNormal(geometry);
-
-
<static> createAttributeIndices
-
Creates an object that maps attribute names to unique indices for matching vertex attributes and shader programs.
Parameters:
Name Type Description geometry
Geometry The geometry, which is not modified, to create the object for. Throws:
DeveloperError : geometry is required.Returns:
Object An object with attribute name / index pairs.Example
var attributeIndices = GeometryPipeline.createAttributeIndices(geometry); // Example output // { // 'position' : 0, // 'normal' : 1 // }
-
<static> createLineSegmentsForVectors
-
Creates a new Geometry with
LINES
representing the provided attribute (attributeName
) for the provided geometry. This is used to visualize vector attributes like normals, binormals, and tangents.Parameters:
Name Type Argument Default Description geometry
Geometry The Geometry
instance with the attribute.attributeName
String <optional>
'normal' The name of the attribute. length
Number <optional>
10000.0 The length of each line segment in meters. This can be negative to point the vector in the opposite direction. Throws:
-
DeveloperError : geometry is required.
-
DeveloperError : geometry.attributes.position is required.
-
DeveloperError : geometry.attributes must have an attribute with the same name as the attributeName parameter.
Returns:
Geometry A newGeometry
instance with line segments for the vector.
Example
var geometry = GeometryPipeline.createLineSegmentsForVectors(instance.geometry, 'binormal', 100000.0),
-
-
<static> encodeAttribute
-
Encodes floating-point geometry attribute values as two separate attributes to improve rendering precision using the same encoding as EncodedCartesian3.
This is commonly used to create high-precision position vertex attributes.
Parameters:
Name Type Description geometry
Geometry The geometry to modify. attributeName
String The name of the attribute. attributeHighName
String The name of the attribute for the encoded high bits. attributeLowName
String The name of the attribute for the encoded low bits. Throws:
-
DeveloperError : geometry is required.
-
DeveloperError : attributeName is required.
-
DeveloperError : attributeHighName is required.
-
DeveloperError : attributeLowName is required.
-
DeveloperError : geometry must have attribute matching the attributeName argument.
-
DeveloperError : The attribute componentDatatype must be ComponentDatatype.DOUBLE.
Returns:
Geometry The modifiedgeometry
argument, with its encoded attribute.Example
geometry = GeometryPipeline.encodeAttribute(geometry, 'position3D', 'position3DHigh', 'position3DLow');
See:
-
-
<static> fitToUnsignedShortIndices
-
Splits a geometry into multiple geometries, if necessary, to ensure that indices in the
indices
fit into unsigned shorts. This is used to meet the WebGL requirements when Context#getElementIndexUint isfalse
.If the geometry does not have any
indices
, this function has no effect.Parameters:
Name Type Description geometry
Geometry The geometry to be split into multiple geometries. Throws:
-
DeveloperError : geometry is required.
-
DeveloperError : geometry.primitiveType must equal to PrimitiveType.TRIANGLES, PrimitiveType.LINES, or PrimitiveType.POINTS
-
DeveloperError : All geometry attribute lists must have the same number of attributes.
Returns:
Array An array of geometries, each with indices that fit into unsigned shorts.Example
var geometries = GeometryPipeline.fitToUnsignedShortIndices(geometry);
-
-
<static> projectTo2D
-
Projects a geometry's 3D
position
attribute to 2D, replacing theposition
attribute with separateposition3D
andposition2D
attributes.If the geometry does not have a
position
, this function has no effect.Parameters:
Name Type Argument Default Description geometry
Geometry The geometry to modify. projection
Object <optional>
new GeographicProjection() The projection to use. Throws:
DeveloperError : geometry is required.Returns:
Example
geometry = GeometryPipeline.projectTo2D(geometry);
-
<static> reorderForPostVertexCache
-
Reorders a geometry's
indices
to achieve better performance from the GPU's post vertex-shader cache by using the Tipsify algorithm. If the geometryprimitiveType
is notTRIANGLES
or the geometry does not have anindices
, this function has no effect.Parameters:
Name Type Argument Default Description geometry
Geometry The geometry to modify. cacheCapacity
Number <optional>
24 The number of vertices that can be held in the GPU's vertex cache. Throws:
-
DeveloperError : geometry is required.
-
DeveloperError : cacheCapacity must be greater than two.
Returns:
Geometry The modifiedgeometry
argument, with its indices reordered for the post-vertex-shader cache.Example
geometry = GeometryPipeline.reorderForPostVertexCache(geometry);
- GeometryPipeline.reorderForPreVertexCache
- Fast Triangle Reordering for Vertex Locality and Reduced Overdraw by Sander, Nehab, and Barczak
See:
-
-
<static> reorderForPreVertexCache
-
Reorders a geometry's attributes and
indices
to achieve better performance from the GPU's pre-vertex-shader cache.Parameters:
Name Type Description geometry
Geometry The geometry to modify. Throws:
-
DeveloperError : geometry is required.
-
DeveloperError : Each attribute array in geometry.attributes must have the same number of attributes.
Returns:
Geometry The modifiedgeometry
argument, with its attributes and indices reordered for the GPU's pre-vertex-shader cache.Example
geometry = GeometryPipeline.reorderForPreVertexCache(geometry);
-
-
<static> toWireframe
-
Converts a geometry's triangle indices to line indices. If the geometry has an
indices
and itsprimitiveType
isTRIANGLES
,TRIANGLE_STRIP
,TRIANGLE_FAN
, it is converted toLINES
; otherwise, the geometry is not changed.This is commonly used to create a wireframe geometry for visual debugging.
Parameters:
Name Type Description geometry
Geometry The geometry to modify. Throws:
-
DeveloperError : geometry is required.
-
DeveloperError : geometry.primitiveType must be TRIANGLES, TRIANGLE_STRIP, or TRIANGLE_FAN.
Returns:
Geometry The modifiedgeometry
argument, with its triangle indices converted to lines.Example
geometry = GeometryPipeline.toWireframe(geometry);
-
-
<static> transformToWorldCoordinates
-
Transforms a geometry instance to world coordinates. This is used as a prerequisite to batch together several instances with GeometryPipeline.combine. This changes the instance's
modelMatrix
to {@see Matrix4.IDENTITY} and transforms the following attributes if they are present:position
,normal
,binormal
, andtangent
.Parameters:
Name Type Description instance
GeometryInstance The geometry instance to modify. Throws:
DeveloperError : instance is required.Returns:
GeometryInstance The modifiedinstance
argument, with its attributes transforms to world coordinates.Example
for (var i = 0; i < instances.length; ++i) { GeometryPipeline.transformToWorldCoordinates(instances[i]); } var geometry = GeometryPipeline.combine(instances);
-
<static> wrapLongitude
-
Splits the geometry's primitives, by introducing new vertices and indices,that intersect the International Date Line so that no primitives cross longitude -180/180 degrees. This is not required for 3D drawing, but is required for correcting drawing in 2D and Columbus view.
Parameters:
Name Type Description geometry
Geometry The geometry to modify. Throws:
DeveloperError : geometry is required.Returns:
Geometry The modifiedgeometry
argument, with it's primitives split at the International Date Line.Example
geometry = GeometryPipeline.wrapLongitude(geometry);