Class BufferGeometry<Attributes>

A representation of mesh, line, or point geometry Includes vertex positions, face indices, normals, colors, UVs, and custom attributes within buffers, reducing the cost of passing all this data to the GPU.

Remarks

To read and edit data in BufferGeometry attributes, see BufferAttribute documentation.

Example

const geometry = new THREE.BufferGeometry();

// create a simple square shape. We duplicate the top left and bottom right
// vertices because each vertex needs to appear once per triangle.
const vertices = new Float32Array( [
-1.0, -1.0, 1.0, // v0
1.0, -1.0, 1.0, // v1
1.0, 1.0, 1.0, // v2

1.0, 1.0, 1.0, // v3
-1.0, 1.0, 1.0, // v4
-1.0, -1.0, 1.0 // v5
] );

// itemSize = 3 because there are 3 values (components) per vertex
geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
const material = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
const mesh = new THREE.Mesh( geometry, material );

Example

const geometry = new THREE.BufferGeometry();

const vertices = new Float32Array( [
-1.0, -1.0, 1.0, // v0
1.0, -1.0, 1.0, // v1
1.0, 1.0, 1.0, // v2
-1.0, 1.0, 1.0, // v3
] );
geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );

const indices = [
0, 1, 2,
2, 3, 0,
];

geometry.setIndex( indices );
geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );

const material = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
const mesh = new THREE.Mesh( geometry, material );

See

Type Parameters

Hierarchy (view full)

Constructors

Properties

attributes: Attributes

This hashmap has as id the name of the attribute to be set and as value the buffer to set it to. Rather than accessing this property directly, use .setAttribute and .getAttribute to access attributes of this geometry.

Default Value

{}

boundingBox: null | Box3

Bounding box for the BufferGeometry, which can be calculated with .computeBoundingBox().

Remarks

Bounding boxes aren't computed by default. They need to be explicitly computed, otherwise they are null.

Default Value

null

boundingSphere: null | Sphere

Bounding sphere for the BufferGeometry, which can be calculated with .computeBoundingSphere().

Remarks

bounding spheres aren't computed by default. They need to be explicitly computed, otherwise they are null.

Default Value

null

drawRange: {
    count: number;
    start: number;
}

Determines the part of the geometry to render. This should not be set directly, instead use .setDrawRange(...).

Type declaration

  • count: number
  • start: number

Remarks

For non-indexed BufferGeometry, count is the number of vertices to render.

Default Value

{ start: 0, count: Infinity }

groups: {
    count: number;
    materialIndex?: number;
    start: number;
}[]

Split the geometry into groups, each of which will be rendered in a separate WebGL draw call. This allows an array of materials to be used with the geometry.

Type declaration

  • count: number

    Specifies how many vertices (or indices) are included.

    Remarks

    Expects a Integer

  • Optional materialIndex?: number

    Specifies the material array index to use.

    Remarks

    Expects a Integer

  • start: number

    Specifies the first element in this draw call – the first vertex for non-indexed geometry, otherwise the first triangle index.

    Remarks

    Expects a Integer

Remarks

Every vertex and index must belong to exactly one group — groups must not share vertices or indices, and must not leave vertices or indices unused.

Default Value

[]

id: number

Unique number for this BufferGeometry instance.

Remarks

Expects a Integer

index: null | BufferAttribute

Allows for vertices to be re-used across multiple triangles; this is called using "indexed triangles". Each triangle is associated with the indices of three vertices. This attribute therefore stores the index of each vertex for each triangular face. If this attribute is not set, the renderer assumes that each three contiguous positions represent a single triangle.

Default Value

null

isBufferGeometry: true

Read-only flag to check if a given object is of type BufferGeometry.

Remarks

This is a constant value

Default Value

true

morphAttributes: {
    [name: string]: (BufferAttribute | InterleavedBufferAttribute)[];
}

Hashmap of BufferAttributes holding details of the geometry's morph targets.

Type declaration

Remarks

Once the geometry has been rendered, the morph attribute data cannot be changed. You will have to call .dispose(), and create a new instance of BufferGeometry.

Default Value

{}

morphTargetsRelative: boolean

Used to control the morph target behavior; when set to true, the morph target data is treated as relative offsets, rather than as absolute positions/normals.

Default Value

false

name: string

Optional name for this BufferGeometry instance.

Default Value

''

type: string

A Read-only string to check if this object type.

Remarks

Sub-classes will update this value.

Default Value

BufferGeometry

userData: Record<string, any>

An object that can be used to store custom data about the BufferGeometry. It should not hold references to functions as these will not be cloned.

Default Value

{}

uuid: string

UUID of this object instance.

Remarks

This gets automatically assigned and shouldn't be edited.

Methods

  • Adds a group to this geometry

    Parameters

    • start: number
    • count: number
    • Optional materialIndex: number

    Returns void

    See

    the groups property for details.

  • Applies the matrix transform to the geometry.

    Parameters

    Returns this

  • Applies the rotation represented by the quaternion to the geometry.

    Parameters

    Returns this

  • Center the geometry based on the bounding box.

    Returns this

  • Clears all groups.

    Returns void

  • Creates a clone of this BufferGeometry

    Returns this

  • Computes bounding box of the geometry, updating .boundingBox attribute.

    Returns void

    Remarks

    Bounding boxes aren't computed by default. They need to be explicitly computed, otherwise they are null.

  • Computes bounding sphere of the geometry, updating .boundingSphere attribute.

    Returns void

    Remarks

    bounding spheres aren't computed by default. They need to be explicitly computed, otherwise they are null.

  • Calculates and adds a tangent attribute to this geometry. The computation is only supported for indexed geometries and if position, normal, and uv attributes are defined

    Returns void

    Remarks

    When using a tangent space normal map, prefer the MikkTSpace algorithm provided by BufferGeometryUtils.computeMikkTSpaceTangents instead.

  • Computes vertex normals for the given vertex data. For indexed geometries, the method sets each vertex normal to be the average of the face normals of the faces that share that vertex. For non-indexed geometries, vertices are not shared, and the method sets each vertex normal to be the same as the face normal.

    Returns void

  • Copies another BufferGeometry to this BufferGeometry.

    Returns this

  • Deletes the attribute with the specified name.

    Parameters

    Returns this

  • Fire an event type.

    Type Parameters

    • T extends "dispose"

    Parameters

    • event: BaseEvent<T> & {
          dispose: {};
      }[T]

      The event that gets fired.

    Returns void

  • Frees the GPU-related resources allocated by this instance.

    Returns void

    Remarks

    Call this method whenever this instance is no longer used in your app.

  • Returns the attribute with the specified name.

    Type Parameters

    • K extends string | number | symbol

    Parameters

    • name: K

    Returns Attributes[K]

  • Returns true if the attribute with the specified name exists.

    Parameters

    Returns boolean

  • Checks if listener is added to an event type.

    Type Parameters

    • T extends "dispose"

    Parameters

    Returns boolean

  • Type Parameters

    • T extends string

    Parameters

    Returns boolean

  • Rotates the geometry to face a point in space.

    Parameters

    • vector: Vector3

      A world vector to look at.

    Returns this

    Remarks

    This is typically done as a one time operation, and not during a loop.

  • Every normal vector in a geometry will have a magnitude of 1

    Returns void

    Remarks

    This will correct lighting on the geometry surfaces.

  • Rotate the geometry about the X axis. This is typically done as a one time operation, and not during a loop.

    Parameters

    • angle: number

      radians. Expects a Float

    Returns this

    Remarks

    Use Object3D.rotation for typical real-time mesh rotation.

  • Rotate the geometry about the Y axis.

    Parameters

    • angle: number

      radians. Expects a Float

    Returns this

    Remarks

    This is typically done as a one time operation, and not during a loop.

  • Rotate the geometry about the Z axis.

    Parameters

    • angle: number

      radians. Expects a Float

    Returns this

    Remarks

    This is typically done as a one time operation, and not during a loop.

  • Scale the geometry data.

    Parameters

    • x: number

      Expects a Float

    • y: number

      Expects a Float

    • z: number

      Expects a Float

    Returns this

    Remarks

    This is typically done as a one time operation, and not during a loop.

  • Sets an attribute to this geometry with the specified name.

    Type Parameters

    • K extends string | number | symbol

    Parameters

    Returns this

    Remarks

    Use this rather than the attributes property, because an internal hashmap of .attributes is maintained to speed up iterating over attributes.

  • Set the .drawRange property

    Parameters

    • start: number
    • count: number

      is the number of vertices or indices to render. Expects a Integer

    Returns void

    Remarks

    For non-indexed BufferGeometry, count is the number of vertices to render

  • Sets the attributes for this BufferGeometry from an array of points.

    Parameters

    Returns this

  • Set the .index buffer.

    Parameters

    Returns this

  • Convert the buffer geometry to three.js JSON Object/Scene format.

    Returns {}

    • Translate the geometry.

      Parameters

      • x: number

        Expects a Float

      • y: number

        Expects a Float

      • z: number

        Expects a Float

      Returns this

      Remarks

      This is typically done as a one time operation, and not during a loop.