three.js BufferGeometry

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 );

构造函数

BufferGeometry()

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

属性

.attributes : Object

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

.boundingBox : Box3

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

.boundingSphere : Sphere

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

.drawRange : Object

用于判断几何体的哪个部分需要被渲染。该值不应该直接被设置,而需要通过 .setDrawRange 进行设置。
默认值为

{ start: 0, count: Infinity }

.groups : Array

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

分割后的每个部分都是一个如下的表单:

{ start: Integer, count: Integer, materialIndex: Integer }

start 表明当前 draw call 中的没有索引的几何体的几何体的第一个顶点;或者第一个三角面片的索引。 count 指明当前分割包含多少顶点(或 indices)。 materialIndex 指出当前用到的材质队列的索引。

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

<!-- Note: groups used to be called drawCalls

.drawcalls : Array

For geometries that use indexed triangles, this Array can be used to split the object into multiple WebGL draw calls. Each draw call will draw some subset of the vertices in this geometry using the configured shader. This may be necessary if, for instance, you have more than 65535 vertices in your object.

-->

.id : Integer

当前 bufferGeometry 的唯一编号。

.index : BufferAttribute

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

.morphAttributes : Object

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

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

.name : String

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

.userData : Object

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

.uuid : String

当前对象实例的 UUID,该值会自动被分配,且不应被修改。

方法

EventDispatcher 在该类上可用的所有方法。

.setAttribute ( name : String, attribute : BufferAttribute ) : BufferGeometry

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

.addGroup ( start : Integer, count : Integer, materialIndex : Integer ) : null

为当前几何体增加一个 group,详见 groups 属性。

.applyMatrix4 ( matrix : Matrix4 ) : null

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

.center () : BufferGeometry

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

.clone () : BufferGeometry

克隆当前的 BufferGeometry。

.copy ( bufferGeometry : BufferGeometry ) : BufferGeometry

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

.clearGroups ( ) : null

清空所有的 groups。

.computeBoundingBox () : null

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

.computeBoundingSphere () : null

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

.computeTangents () : 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.

.computeVertexNormals () : null

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

.dispose () : null

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

.getAttribute ( name : String ) : BufferAttribute

返回指定名称的 attribute。

.getIndex () : BufferAttribute

返回缓存相关的 .index。

.hasAttribute ( name : String ) : Boolean

Returns true if the attribute with the specified name exists.

.lookAt ( vector : Vector3 ) : BufferGeometry

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

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

.merge ( bufferGeometry : BufferGeometry, offset : Integer ) : null

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

.normalizeNormals () : null

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

.deleteAttribute ( name : String ) : BufferAttribute

删除具有指定名称的 attribute。

.rotateX ( radians : Float ) : BufferGeometry

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

.rotateY ( radians : Float ) : BufferGeometry

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

.rotateZ ( radians : Float ) : BufferGeometry

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

.scale ( x : Float, y : Float, z : Float ) : BufferGeometry

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

.setIndex ( index : BufferAttribute ) : BufferGeometry

设置缓存的 .index。

.setDrawRange ( start : Integer, count : Integer ) : null

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

.setFromPoints ( points : Array ) : BufferGeometry

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

.toJSON () : Object

返回代表该 BufferGeometry 的 JSON 对象。

.toNonIndexed () : BufferGeometry

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

.translate ( x : Float, y : Float, z : Float ) : BufferGeometry

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值