[name]

An efficient 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.

To read and edit data in BufferGeometry attributes, see [page:BufferAttribute] documentation.

For a less efficient but easier-to-use representation of geometry, see [page:Geometry].

Example

var 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. var vertices = new Float32Array( [ -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0 ] ); // itemSize = 3 because there are 3 values (components) per vertex geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) ); var material = new THREE.MeshBasicMaterial( { color: 0xff0000 } ); var mesh = new THREE.Mesh( geometry, material );

[example:webgl_buffergeometry Mesh with non-indexed faces]
[example:webgl_buffergeometry_indexed Mesh with indexed faces]
[example:webgl_buffergeometry_lines Lines]
[example:webgl_buffergeometry_lines_indexed Indexed Lines]
[example:webgl_buffergeometry_custom_attributes_particles Particles]
[example:webgl_buffergeometry_rawshader Raw Shaders]

Constructor

[name]()

This creates a new [name]. It also sets several properties to a default value.

Properties

[property:Object attributes]

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

[property:Box3 boundingBox]

Bounding box for the bufferGeometry, which can be calculated with [page:.computeBoundingBox](). Default is *null*.

[property:Sphere boundingSphere]

Bounding sphere for the bufferGeometry, which can be calculated with [page:.computeBoundingSphere](). Default is *null*.

[property:Object drawRange]

Determines the part of the geometry to render. This should not be set directly, instead use [page:.setDrawRange]. Default is { start: 0, count: Infinity } For non-indexed BufferGeometry, count is the number of vertices to render. For indexed BufferGeometry, count is the number of indices to render.

[property:Array groups]

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 bufferGeometry.

Each group is an object of the form: { start: Integer, count: Integer, materialIndex: Integer } where start specifies the first element in this draw call – the first vertex for non-indexed geometry, otherwise the first triangle index. Count specifies how many vertices (or indices) are included, and materialIndex specifies the material array index to use.

Use [page:.addGroup] to add groups, rather than modifying this array directly.

[property:Integer id]

Unique number for this bufferGeometry instance.

[property:BufferAttribute index]

Allows for vertices to be re-used across multiple triangles; this is called using "indexed triangles" and works much the same as it does in [page:Geometry]: 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 [page:WebGLRenderer renderer] assumes that each three contiguous positions represent a single triangle. Default is *null*.

[property:Boolean isBufferGeometry]

Used to check whether this or derived classes are BufferGeometries. Default is *true*.

You should not change this, as it used internally for optimisation.

[property:Object morphAttributes]

Hashmap of [page:BufferAttribute]s holding details of the geometry's [page:Geometry.morphTargets morphTargets].

[property:String name]

Optional name for this bufferGeometry instance. Default is an empty string.

[property:Object userData]

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.

[property:String uuid]

[link:http://en.wikipedia.org/wiki/Universally_unique_identifier UUID] of this object instance. This gets automatically assigned and shouldn't be edited.

Methods

[page:EventDispatcher EventDispatcher] methods are available on this class.

[method:BufferGeometry addAttribute]( [param:String name], [param:BufferAttribute attribute] )

Adds an attribute to this geometry. Use this rather than the attributes property, because an internal hashmap of [page:.attributes] is maintained to speed up iterating over attributes.

[method:null addGroup]( [param:Integer start], [param:Integer count], [param:Integer materialIndex] )

Adds a group to this geometry; see the [page:BufferGeometry.groups groups] property for details.

[method:null applyMatrix]( [param:Matrix4 matrix] )

Bakes matrix transform directly into vertex coordinates.

[method:BufferGeometry center] ()

Center the geometry based on the bounding box.

[method:BufferGeometry clone]()

Creates a clone of this BufferGeometry.

[method:BufferGeometry copy]( [param:BufferGeometry bufferGeometry] )

Copies another BufferGeometry to this BufferGeometry.

[method:null clearGroups]( )

Clears all groups.

[method:null computeBoundingBox]()

Computes bounding box of the geometry, updating [page:.boundingBox] attribute.
Bounding boxes aren't computed by default. They need to be explicitly computed, otherwise they are *null*.

[method:null computeBoundingSphere]()

Computes bounding sphere of the geometry, updating [page:.boundingSphere] attribute.
Bounding spheres aren't computed by default. They need to be explicitly computed, otherwise they are *null*.

[method:null computeVertexNormals]()

Computes vertex normals by averaging face normals.

[method:null dispose]()

Disposes the object from memory.
You need to call this when you want the BufferGeometry removed while the application is running.

[method:BufferGeometry fromDirectGeometry]( [param:Geometry] )

Populates this BufferGeometry with data from a [page:DirectGeometry] object containing faces. Not implemented for a line geometry.

Note: [page:DirectGeometry] is mainly used as an intermediary object for converting between [page:Geometry] and BufferGeometry.

[method:BufferGeometry fromGeometry]( [param:Geometry] )

Populates this BufferGeometry with data from a [page:Geometry] object containing faces. Not implemented for a line geometry.

[method:BufferAttribute getAttribute]( [param:String name] )

Returns the [page:BufferAttribute attribute] with the specified name.

[method:BufferAttribute getIndex] ()

Return the [page:.index] buffer.

[method:BufferGeometry lookAt] ( [param:Vector3 vector] )

vector - A world vector to look at.

Rotates the geometry to face a point in space. This is typically done as a one time operation, and not during a loop. Use [page:Object3D.lookAt] for typical real-time mesh usage.

[method:null merge]( [param:BufferGeometry bufferGeometry], [param:Integer offset] )

Merge in another BufferGeometry with an optional offset of where to start merging in.

[method:null normalizeNormals]()

Every normal vector in a geometry will have a magnitude of 1. This will correct lighting on the geometry surfaces.

[method:BufferAttribute removeAttribute]( [param:String name] )

Removes the [page:BufferAttribute attribute] with the specified name.

[method:BufferGeometry rotateX] ( [param:Float radians] )

Rotate the geometry about the X axis. This is typically done as a one time operation, and not during a loop. Use [page:Object3D.rotation] for typical real-time mesh rotation.

[method:BufferGeometry rotateY] ( [param:Float radians] )

Rotate the geometry about the Y axis. This is typically done as a one time operation, and not during a loop. Use [page:Object3D.rotation] for typical real-time mesh rotation.

[method:BufferGeometry rotateZ] ( [param:Float radians] )

Rotate the geometry about the Z axis. This is typically done as a one time operation, and not during a loop. Use [page:Object3D.rotation] for typical real-time mesh rotation.

[method:BufferGeometry scale] ( [param:Float x], [param:Float y], [param:Float z] )

Scale the geometry data. This is typically done as a one time operation, and not during a loop. Use [page:Object3D.scale] for typical real-time mesh scaling.

[method:null setIndex] ( [param:BufferAttribute index] )

Set the [page:.index] buffer.

[method:null setDrawRange] ( [param:Integer start], [param:Integer count] )

Set the [page:.drawRange] property. For non-indexed BufferGeometry, count is the number of vertices to render. For indexed BufferGeometry, count is the number of indices to render.

[method:BufferGeometry setFromObject] ( [param:Object3D object] )

Sets the attributes for this BufferGeometry from an [page:Object3D].

[method:BufferGeometry setFromPoints] ( [param:Array points] )

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

[method:Object toJSON]()

Convert the buffer geometry to three.js [link:https://github.com/mrdoob/three.js/wiki/JSON-Object-Scene-format-4 JSON Object/Scene format].

[method:BufferGeometry toNonIndexed]()

Return a non-index version of an indexed BufferGeometry.

[method:BufferGeometry translate] ( [param:Float x], [param:Float y], [param:Float z] )

Translate the geometry. This is typically done as a one time operation, and not during a loop. Use [page:Object3D.position] for typical real-time mesh translation.

[method:BufferGeometry updateFromObject] ( [param:Object3D object] )

Updates the attributes for this BufferGeometry from an [page:Object3D].

Source

[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]