[name]

是面片、线或点几何体的有效表述。包括顶点位置,面片索引、法相量、颜色值、UV 坐标和自定义缓存属性值。使用 BufferGeometry 可以有效减少向 GPU 传输上述数据所需的开销。

读取或编辑 BufferGeometry 中的数据,见 [page:BufferAttribute] 文档。

代码示例

const geometry = new THREE.BufferGeometry(); // 创建一个简单的矩形. 在这里我们左上和右下顶点被复制了两次。 // 因为在两个三角面片里,这两个顶点都需要被用到。 const 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 因为每个顶点都是一个三元组。 geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) ); const material = new THREE.MeshBasicMaterial( { color: 0xff0000 } ); const 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]

构造函数

[name]()

创建一个新的 [name]. 同时将预置属性设置为默认值.

属性

[property:Object attributes]

通过 hashmap 存储该几何体相关的属性,hashmap 的 id 是当前 attribute 的名称,值是相应的 [page:BufferAttribute buffer]。 你可以通过 [page:.setAttribute] 和 [page:.getAttribute] 添加和访问与当前几何体有关的 attribute。

[property:Box3 boundingBox]

当前 bufferGeometry 的外边界矩形。可以通过 [page:.computeBoundingBox]() 计算。默认值是 *null*。

[property:Sphere boundingSphere]

当前 bufferGeometry 的外边界球形。可以通过 [page:.computeBoundingSphere]() 计算。默认值是 *null*。

[property:Object drawRange]

用于判断几何体的哪个部分需要被渲染。该值不应该直接被设置,而需要通过 [page:.setDrawRange] 进行设置。
默认值为 { start: 0, count: Infinity }

[property:Array groups]

将当前几何体分割成组进行渲染,每个部分都会在单独的 WebGL 的 draw call 中进行绘制。该方法可以让当前的 bufferGeometry 可以使用一个材质队列进行描述。

分割后的每个部分都是一个如下的表单: { start: Integer, count: Integer, materialIndex: Integer } start 表明当前 draw call 中的没有索引的几何体的几何体的第一个顶点;或者第一个三角面片的索引。 count 指明当前分割包含多少顶点(或 indices)。 materialIndex 指出当前用到的材质队列的索引。

通过 [page:.addGroup] 来增加组,而不是直接更改当前队列。

[property:Integer id]

当前 bufferGeometry 的唯一编号。

[property:BufferAttribute index]

允许顶点在多个三角面片间可以重用。这样的顶点被称为"已索引的三角面片(indexed triangles)。 每个三角面片都和三个顶点的索引相关。该 attribute 因此所存储的是每个三角面片的三个顶点的索引。 如果该 attribute 没有设置过,则 [page:WebGLRenderer renderer] 假设每三个连续的位置代表一个三角面片。 默认值是 *null*。

[property:Object morphAttributes]

存储 [page:BufferAttribute] 的 Hashmap,存储了几何体 morph targets 的细节信息。

[property:Boolean morphTargetsRelative]

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 is *false*.

[property:String name]

当前 bufferGeometry 实例的可选别名。默认值是空字符串。

[property:Object userData]

存储 BufferGeometry 的自定义数据的对象。为保持对象在克隆时完整,该对象不应该包括任何函数的引用。

[property:String uuid]

当前对象实例的 [link:http://en.wikipedia.org/wiki/Universally_unique_identifier UUID],该值会自动被分配,且不应被修改。

方法

[page:EventDispatcher EventDispatcher] 在该类上可用的所有方法。

[method:this setAttribute]( [param:String name], [param:BufferAttribute attribute] )

为当前几何体设置一个 attribute 属性。在类的内部,有一个存储 [page:.attributes] 的 hashmap, 通过该 hashmap,遍历 attributes 的速度会更快。而使用该方法,可以向 hashmap 内部增加 attribute。 所以,你需要使用该方法来添加 attributes。

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

为当前几何体增加一个 group,详见 [page:BufferGeometry.groups groups] 属性。

[method:this applyMatrix4]( [param:Matrix4 matrix] )

用给定矩阵转换几何体的顶点坐标。

[method:this center] ()

根据边界矩形将几何体居中。

[method:BufferGeometry clone]()

克隆当前的 BufferGeometry。

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

将参数指定的 BufferGeometry 的值拷贝到当前 BufferGeometry 中。

[method:undefined clearGroups]( )

清空所有的 groups。

[method:undefined computeBoundingBox]()

计算当前几何体的的边界矩形,该操作会更新已有 [param:.boundingBox]。
边界矩形不会默认计算,需要调用该接口指定计算边界矩形,否则保持默认值 *null*。

[method:undefined computeBoundingSphere]()

计算当前几何体的的边界球形,该操作会更新已有 [param:.boundingSphere]。
边界球形不会默认计算,需要调用该接口指定计算边界球形,否则保持默认值 *null*。

[method:undefined computeTangents]()

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.

[method:undefined computeVertexNormals]()

通过面片法向量的平均值计算每个顶点的法向量。

[method:undefined dispose]()

从内存中销毁对象。
如果在运行是需要从内存中删除 BufferGeometry,则需要调用该函数。

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

返回指定名称的 [page:BufferAttribute attribute]。

[method:BufferAttribute getIndex] ()

返回缓存相关的 [page:.index]。

[method:Boolean hasAttribute]( [param:String name] )

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

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

vector - 几何体所朝向的世界坐标。

旋转几何体朝向控件中的一点。该过程通常在一次处理中完成,不会循环处理。典型的用法是过通过调用 [page:Object3D.lookAt] 实时改变 mesh 朝向。

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

同参数指定的 BufferGeometry 进行合并。可以通过可选参数指定,从哪个偏移位置开始进行 merge。

[method:undefined normalizeNormals]()

几何体中的每个法向量长度将会为 1。这样操作会更正光线在表面的效果。

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

删除具有指定名称的 [page:BufferAttribute attribute]。

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

在 X 轴上旋转几何体。该操作一般在一次处理中完成,不会循环处理。典型的用法是通过调用 [page:Object3D.rotation] 实时旋转几何体。

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

在 Y 轴上旋转几何体。该操作一般在一次处理中完成,不会循环处理。典型的用法是通过调用 [page:Object3D.rotation] 实时旋转几何体。

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

在 Z 轴上旋转几何体。该操作一般在一次处理中完成,不会循环处理。典型的用法是通过调用 [page:Object3D.rotation] 实时旋转几何体。

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

缩放几何体。该操作一般在一次处理中完成,不会循环处理。典型的用法是通过调用 [page:Object3D.scale] 实时旋转几何体。

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

设置缓存的 [page:.index]。

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

设置缓存的 [page:.drawRange]。详见相关属性说明。

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

通过点队列设置该 BufferGeometry 的 attribute。

[method:Object toJSON]()

返回代表该 BufferGeometry 的 JSON 对象。

[method:BufferGeometry toNonIndexed]()

返回已索引的 BufferGeometry 的非索引版本。

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

移动几何体。该操作一般在一次处理中完成,不会循环处理。典型的用法是通过调用 [page:Object3D.rotation] 实时旋转几何体。

Source

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