Capítulo 23 de 859
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.
computeBoundingBox().computeBoundingSphere().setDrawRange().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 );
Constructor
| Signature |
|---|
new BufferGeometry() |
Properties
| Property | Description |
|---|---|
| `.attributes : Object.<string, (BufferAttribute | InterleavedBufferAttribute)>` |
.boundingBox : Box3 | Bounding box for the geometry which can be calculated with computeBoundingBox(). |
.boundingSphere : Sphere | Bounding sphere for the geometry which can be calculated with computeBoundingSphere(). |
.drawRange : Object | Determines the part of the geometry to render. This should not be set directly, instead use setDrawRange(). |
.groups : Array.<Object> | Split the geometry into groups, each of which will be rendered in a separate draw call. This allows an array of materials to be used with the geometry. |
.id : number (readonly) | The ID of the geometry. |
.index : 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 … |
.indirect : BufferAttribute | A (storage) buffer attribute which was generated with a compute shader and now defines indirect draw calls. |
| `.indirectOffset : number | Array.<number>` |
.isBufferGeometry : boolean (readonly) | This flag can be used for type testing. |
.morphAttributes : Object | This dictionary holds the morph targets of the geometry. |
.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. |
.name : string | The name of the geometry. |
.userData : Object | An object that can be used to store custom data about the geometry. It should not hold references to functions as these will not be cloned. |
.uuid : string (readonly) | The UUID of the geometry. |
Methods
| Method | Description |
|---|---|
.addGroup( start : number, count : number, materialIndex : number ) | Adds a group to this geometry. |
.applyMatrix4( matrix : Matrix4 ) : BufferGeometry | Applies the given 4x4 transformation matrix to the geometry. |
.applyQuaternion( q : Quaternion ) : BufferGeometry | Applies the rotation represented by the Quaternion to the geometry. |
.center() : BufferGeometry | Center the geometry based on its bounding box. |
.clearGroups() | Clears all groups. |
.clone() : BufferGeometry | Returns a new geometry with copied values from this instance. |
.computeBoundingBox() | Computes the bounding box of the geometry, and updates the boundingBox member. The bounding box is not computed by the engine; it must be computed by your app. You may need to recompute the boundin… |
.computeBoundingSphere() | Computes the bounding sphere of the geometry, and updates the boundingSphere member. The engine automatically computes the bounding sphere when it is needed, e.g., for ray casting or view frustum c… |
.computeTangents() | Calculates and adds a tangent attribute to this geometry. |
.computeVertexNormals() | 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-indexe… |
.copy( source : BufferGeometry ) : BufferGeometry | Copies the values of the given geometry to this instance. |
.deleteAttribute( name : string ) : BufferGeometry | Deletes the attribute for the given name. |
.dispose() | Frees the GPU-related resources allocated by this instance. Call this method whenever this instance is no longer used in your app. |
| `.getAttribute( name : string ) : BufferAttribute | InterleavedBufferAttribute |
.getIndex() : BufferAttribute | Returns the index of this geometry. |
.getIndirect() : BufferAttribute | Returns the indirect attribute of this geometry. |
.hasAttribute( name : string ) : boolean | Returns true if this geometry has an attribute for the given name. |
.lookAt( vector : Vector3 ) : BufferGeometry | Rotates the geometry to face a point in 3D space. This is typically done as a one time operation, and not during a loop. Use Object3D#lookAt for typical real-time mesh rotatio… |
.normalizeNormals() | Ensures every normal vector in a geometry will have a magnitude of 1. This will correct lighting on the geometry surfaces. |
.rotateX( angle : number ) : BufferGeometry | Rotates the geometry about the X axis. This is typically done as a one time operation, and not during a loop. Use Object3D#rotation for typical real-time mesh rotation. |
.rotateY( angle : number ) : BufferGeometry | Rotates the geometry about the Y axis. This is typically done as a one time operation, and not during a loop. Use Object3D#rotation for typical real-time mesh rotation. |
.rotateZ( angle : number ) : BufferGeometry | Rotates the geometry about the Z axis. This is typically done as a one time operation, and not during a loop. Use Object3D#rotation for typical real-time mesh rotation. |
.scale( x : number, y : number, z : number ) : BufferGeometry | Scales the geometry. This is typically done as a one time operation, and not during a loop. Use Object3D#scale for typical real-time mesh rotation. |
| `.setAttribute( name : string, attribute : BufferAttribute | InterleavedBufferAttribute ) : BufferGeometry` |
.setDrawRange( start : number, count : number ) | Sets the draw range for this geometry. |
| `.setFromPoints( points : Array.<Vector2> | Array.<Vector3> ) : BufferGeometry` |
| `.setIndex( index : Array.<number> | BufferAttribute ) : BufferGeometry` |
| `.setIndirect( indirect : BufferAttribute, indirectOffset : number | Array.<number> ) : BufferGeometry` |
.toJSON() : Object | Serializes the geometry into JSON. |
.toNonIndexed() : BufferGeometry | Return a new non-index version of this indexed geometry. If the geometry is already non-indexed, the method is a NOOP. |
.translate( x : number, y : number, z : number ) : BufferGeometry | Translates the geometry. This is typically done as a one time operation, and not during a loop. Use Object3D#position for typical real-time mesh rotation. |