BufferGeometryUtils

A class containing utility functions for BufferGeometry instances.

Methods

.batchMeshes(meshObjs : Array, batchParent : Object3D)

meshObjs
Array of Mesh objects to be joined together.
batchParent
Container (parent) object to store the batched mesh.

Merges the meshes together to form a batched mesh. This technique is used to reduce the number WebGL draw calls hence to improve rendering performance.

.computeMikkTSpaceTangents(geometry : BufferGeometry, MikkTSpace : Object, negateSign : Boolean = true) → Object

geometry
Instance of BufferGeometry.
MikkTSpace
Instance of examples/jsm/libs/mikktspace.module.js, or mikktspace npm package. Await MikkTSpace.ready before use.
negateSign
Whether to negate the sign component (.w) of each tangent. Required for normal map conventions in some formats, including glTF.

Computes vertex tangents using the MikkTSpace algorithm. MikkTSpace generates the same tangents consistently, and is used in most modelling tools and normal map bakers. Use MikkTSpace for materials with normal maps, because inconsistent tangents may lead to subtle visual issues in the normal map, particularly around mirrored UV seams.

In comparison to this method, BufferGeometry.computeTangents (a custom algorithm) generates tangents that probably will not match the tangents in other software. The custom algorithm is sufficient for general use with a ShaderMaterial, and may be faster than MikkTSpace.

Returns the original BufferGeometry. Indexed geometries will be de-indexed. Requires position, normal, and uv attributes.

.computeMorphedAttributes(object : Mesh | Line | Points) → Object

object — Instance of Mesh, Line, Points.

Returns the current attributes (Position and Normal) of a morphed/skinned Object3D whose geometry is a BufferGeometry, together with the original ones: An Object with 4 properties: positionAttribute, normalAttribute, morphedPositionAttribute and morphedNormalAttribute.

Helpful for Raytracing or Decals (i.e. a DecalGeometry applied to a morphed Object with a BufferGeometry will use the original BufferGeometry, not the morphed/skinned one, generating an incorrect result. Using this function to create a shadow Object3D the DecalGeometry can be correctly generated).

.estimateBytesUsed(geometry : BufferGeometry) → Float

geometry — Instance of BufferGeometry to estimate the memory use of.

Returns the amount of bytes used by all attributes to represent the geometry.

.interleaveAttributes(attributes : Array) → InterleavedBufferAttribute

attributes — Array of BufferAttribute instances.

Interleaves a set of attributes and returns a new array of corresponding attributes that share a single InterleavedBuffer instance. All attributes must have compatible types. If merge does not succeed, the method returns null.

.mergeBufferAttributes(attributes : Array) → BufferAttribute

attributes — Array of BufferAttribute instances.

Merges a set of attributes into a single instance. All attributes must have compatible properties and types, and InterleavedBufferAttributes are not supported. If merge does not succeed, the method returns null.

.mergeBufferGeometries(geometries : Array, useGroups : Boolean) → BufferGeometry

geometries — Array of BufferGeometry instances.
useGroups — Whether groups should be generated for the merged geometry or not.

Merges a set of geometries into a single instance. All geometries must have compatible attributes. If merge does not succeed, the method returns null.

.mergeGroups(geometry : BufferGeometry) → BufferGeometry

geometry — Instance of BufferGeometry to merge the groups of.

Merges the groups for the given geometry.

.mergeVertices(geometry : BufferGeometry, tolerance : Float) → BufferGeometry

geometry — Instance of BufferGeometry to merge the vertices of.
tolerance — The maximum allowable difference between vertex attributes to merge. Defaults to 1e-4.

Returns a new BufferGeometry with vertices for which all similar vertex attributes (within tolerance) are merged.

.toCreasedNormals(geometry : BufferGeometry, creaseAngle : Float) → BufferGeometry

geometry — The input geometry.
creaseAngle — The crease angle.

Creates a new, non-indexed geometry with smooth normals everywhere except faces that meet at an angle greater than the crease angle.

.toTrianglesDrawMode(geometry : BufferGeometry, drawMode : TrianglesDrawMode) → BufferGeometry

geometry — Instance of BufferGeometry.
drawMode — The draw mode of the given geometry. Valid inputs are v3d.TriangleStripDrawMode and v3d.TriangleFanDrawMode.

Returns a new indexed geometry based on v3d.TrianglesDrawMode draw mode. This mode corresponds to the gl.TRIANGLES WebGL primitive.

Source

For more info on how to obtain the source code of this module see this page.