public class BufferGeometry extends AbstractGeometry
Geometry
, because it stores all data, including vertex positions,
face indices, normals, colors, UVs, and custom attributes within buffers; this reduces the cost of passing
all this data to the GPU. This also makes BufferGeometry harder to work with than Geometry
; rather than
accessing position data as Vector3
objects, color data as Color
objects, and so on, you have to access
the raw data from the appropriate attribute buffer BufferAttribute
.
BufferGeometry geometry = new BufferGeometry(); int chunkSize = 20000; // three components per vertex int triangles = 160000; Uint16Array indices = Uint16Array.create( triangles * 3 ); for ( int i = 0; i < indices.getLength(); i ++ ) { indices.set( i, i % ( 3 * chunkSize )); } Float32Array positions = Float32Array.create( triangles * 3 * 3 ); //itemSize = 3 because there are 3 values (components) per vertex geometry.addAttribute( "position", new BufferAttribute( positions, 3 ) );
Modifier and Type | Class and Description |
---|---|
static class |
BufferGeometry.DrawCall |
__colorArray, __lineDistanceArray, __normalArray, __tangentArray, __uv2Array, __uvArray, __vertexArray, __webglColorBuffer, __webglCustomAttributesList, __webglFaceBuffer, __webglFaceCount, __webglInit, __webglLineBuffer, __webglLineCount, __webglLineDistanceBuffer, __webglMorphNormalsBuffers, __webglMorphTargetsBuffers, __webglNormalBuffer, __webglParticleCount, __webglSkinIndicesBuffer, __webglSkinWeightsBuffer, __webglTangentBuffer, __webglUV2Buffer, __webglUVBuffer, __webglVertexBuffer, __webglVertexCount
Constructor and Description |
---|
BufferGeometry() |
Modifier and Type | Method and Description |
---|---|
void |
addAttribute(java.lang.String name,
BufferAttribute attribute)
WebGL stores data associated with individual vertices of a geometry in attributes.
|
void |
addDrawCall(int start,
int count) |
void |
addDrawCall(int start,
int count,
int indexOffset) |
void |
applyMatrix(Matrix4 matrix)
Bakes matrix transform directly into vertex coordinates.
|
BufferGeometry |
clone() |
void |
computeBoundingBox()
Computes bounding box of the geometry, updating Geometry.boundingBox attribute.
|
void |
computeBoundingSphere()
Computes bounding sphere of the geometry, updating Geometry.boundingSphere attribute.
|
java.util.List<BufferGeometry.DrawCall> |
computeOffsets() |
java.util.List<BufferGeometry.DrawCall> |
computeOffsets(int size)
Compute the draw offset for large models by chunking the index buffer into chunks of 65k addressable vertices.
|
void |
computeTangents()
Computes vertex tangents.
|
void |
computeVertexNormals()
Computes vertex normals by averaging face normals.
|
BufferGeometry |
fromGeometry(Geometry geometry)
Populates this BufferGeometry with data from a
Geometry object. |
BufferGeometry |
fromGeometry(Geometry geometry,
Material.COLORS vertexColors) |
BufferAttribute |
getAttribute(java.lang.String name) |
java.util.Map<java.lang.String,BufferAttribute> |
getAttributes() |
java.util.List<BufferGeometry.DrawCall> |
getDrawcalls()
For geometries that use indexed triangles, this Array can be used to split the object into multiple WebGL draw calls.
|
void |
normalizeNormals()
Every normal vector in a geometry will have a magnitude of 1.
|
void |
reorderBuffers(Float32Array indexBuffer,
Int32Array indexMap,
int vertexCount) |
void |
setDirectBuffers(WebGLRenderingContext gl) |
void |
setDrawcalls(java.util.List<BufferGeometry.DrawCall> drawcalls) |
java.lang.String |
toString() |
getBoundingBox, getBoundingSphere, getId, getName, isColorsNeedUpdate, isElementsNeedUpdate, isGroupsNeedUpdate, isLineDistancesNeedUpdate, isMorphTargetsNeedUpdate, isNormalsNeedUpdate, isTangentsNeedUpdate, isUvsNeedUpdate, isVerticesNeedUpdate, setBoundingBox, setBoundingSphere, setColorsNeedUpdate, setElementsNeedUpdate, setGroupsNeedUpdate, setId, setLineDistancesNeedUpdate, setMorphTargetsNeedUpdate, setName, setNormalsNeedUpdate, setTangentsNeedUpdate, setUvsNeedUpdate, setVerticesNeedUpdate
dispose
public java.util.Map<java.lang.String,BufferAttribute> getAttributes()
public void addAttribute(java.lang.String name, BufferAttribute attribute)
Geometry
, the renderer takes care of wrapping up this information into typed array buffers and sending this
data to the shader. With BufferGeometry, all of this data is stored in buffers associated with an individual attributes.
This means that to get the position data associated with a vertex (for instance), you must call .getAttribute() to access
the "position" attribute, then access the individual x, y, and z coordinates of the position.
The following attributes are set by various members of this class:
name
- Attribute nameattribute
- public BufferAttribute getAttribute(java.lang.String name)
public java.util.List<BufferGeometry.DrawCall> getDrawcalls()
public void setDrawcalls(java.util.List<BufferGeometry.DrawCall> drawcalls)
drawcalls
- the drawcalls to setpublic void addDrawCall(int start, int count)
public void addDrawCall(int start, int count, int indexOffset)
public void applyMatrix(Matrix4 matrix)
matrix
- public BufferGeometry fromGeometry(Geometry geometry)
Geometry
object.geometry
- public BufferGeometry fromGeometry(Geometry geometry, Material.COLORS vertexColors)
public void computeBoundingBox()
computeBoundingBox
in class AbstractGeometry
public void computeBoundingSphere()
computeBoundingSphere
in class AbstractGeometry
public void computeVertexNormals()
computeVertexNormals
in class AbstractGeometry
public void computeTangents()
computeTangents
in class AbstractGeometry
public java.util.List<BufferGeometry.DrawCall> computeOffsets()
public java.util.List<BufferGeometry.DrawCall> computeOffsets(int size)
size
- Defaults to 65535, but allows for larger or smaller chunks.public void normalizeNormals()
public void reorderBuffers(Float32Array indexBuffer, Int32Array indexMap, int vertexCount)
public BufferGeometry clone()
clone
in class java.lang.Object
public void setDirectBuffers(WebGLRenderingContext gl)
public java.lang.String toString()
toString
in class AbstractGeometry