@@ -37,6 +37,30 @@ <h2>代码示例</h2>
37
37
const material = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
38
38
const mesh = new THREE.Mesh( geometry, material );
39
39
</ code >
40
+
41
+ < h2 > 代码示例 (索引Index)</ h2 >
42
+
43
+ < code >
44
+ const geometry = new THREE.BufferGeometry();
45
+
46
+ const vertices = new Float32Array( [
47
+ -1.0, -1.0, 1.0, // v0
48
+ 1.0, -1.0, 1.0, // v1
49
+ 1.0, 1.0, 1.0, // v2
50
+ -1.0, 1.0, 1.0, // v3
51
+ ] );
52
+
53
+ const indices = [
54
+ 0, 1, 2,
55
+ 2, 3, 0,
56
+ ];
57
+
58
+ geometry.setIndex( indices );
59
+ geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
60
+
61
+ const material = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
62
+ const mesh = new THREE.Mesh( geometry, material );
63
+ </ code >
40
64
41
65
< h2 > 例子</ h2 >
42
66
< p >
@@ -82,6 +106,8 @@ <h3>[property:Object drawRange]</h3>
82
106
< code >
83
107
{ start: 0, count: Infinity }
84
108
</ code >
109
+ 对于非索引 BufferGeometry,count 是要渲染的顶点数。
110
+ 对于索引 BufferGeometry,count 是要渲染的索引数。
85
111
</ p >
86
112
87
113
< h3 > [property:Array groups]</ h3 >
@@ -94,8 +120,8 @@ <h3>[property:Array groups]</h3>
94
120
start 表明当前 draw call 中的没有索引的几何体的几何体的第一个顶点;或者第一个三角面片的索引。
95
121
count 指明当前分割包含多少顶点(或 indices)。
96
122
materialIndex 指出当前用到的材质队列的索引。< br /> < br />
97
-
98
- 通过 [page:.addGroup] 来增加组,而不是直接更改当前队列 。
123
+ 通过 [page:.addGroup] 来增加组,而不是直接更改当前队列。 < br /> < br />
124
+ 每个顶点和索引必须恰好属于一个组,不同组之间不得共享顶点或索引,并且不得留下未使用的顶点或索引 。
99
125
</ p >
100
126
101
127
@@ -159,54 +185,52 @@ <h2>方法</h2>
159
185
160
186
< p > [page:EventDispatcher EventDispatcher] 在该类上可用的所有方法。</ p >
161
187
162
- < h3 > [method:this setAttribute]( [param:String name], [param:BufferAttribute attribute] )</ h3 >
163
- < p >
164
- 为当前几何体设置一个 attribute 属性。在类的内部,有一个存储 [page:.attributes] 的 hashmap,
165
- 通过该 hashmap,遍历 attributes 的速度会更快。而使用该方法,可以向 hashmap 内部增加 attribute。
166
- 所以,你需要使用该方法来添加 attributes。
167
- </ p >
168
-
169
188
< h3 > [method:undefined addGroup]( [param:Integer start], [param:Integer count], [param:Integer materialIndex] )</ h3 >
170
189
< p >
171
190
为当前几何体增加一个 group,详见 [page:BufferGeometry.groups groups] 属性。
172
191
</ p >
173
192
174
-
175
193
< h3 > [method:this applyMatrix4]( [param:Matrix4 matrix] )</ h3 >
176
194
< p > 用给定矩阵转换几何体的顶点坐标。</ p >
177
195
196
+ < h3 > [method:this applyQuaternion]( [param:Quaternion quaternion] )</ h3 >
197
+ < p > 用给四元数表示的旋转应用于几何体的顶点坐标。</ p >
198
+
178
199
< h3 > [method:this center] ()</ h3 >
179
200
< p > 根据边界矩形将几何体居中。</ p >
201
+
202
+ < h3 > [method:undefined clearGroups]( )</ h3 >
203
+ < p > 清空所有的 groups。</ p >
180
204
181
205
< h3 > [method:BufferGeometry clone]()</ h3 >
182
206
< p > 克隆当前的 BufferGeometry。</ p >
183
207
184
- < h3 > [method:this copy]( [param:BufferGeometry bufferGeometry] )</ h3 >
185
- < p > 将参数指定的 BufferGeometry 的值拷贝到当前 BufferGeometry 中。</ p >
186
-
187
- < h3 > [method:undefined clearGroups]( )</ h3 >
188
- < p > 清空所有的 groups。</ p >
189
-
190
208
< h3 > [method:undefined computeBoundingBox]()</ h3 >
191
209
< p >
192
- 计算当前几何体的的边界矩形,该操作会更新已有 [param :.boundingBox]。< br />
210
+ 计算当前几何体的的边界矩形,该操作会更新已有 [page :.boundingBox]。< br />
193
211
边界矩形不会默认计算,需要调用该接口指定计算边界矩形,否则保持默认值 *null*。
194
212
</ p >
195
213
196
214
< h3 > [method:undefined computeBoundingSphere]()</ h3 >
197
215
< p >
198
- 计算当前几何体的的边界球形,该操作会更新已有 [param :.boundingSphere]。< br />
216
+ 计算当前几何体的的边界球形,该操作会更新已有 [page :.boundingSphere]。< br />
199
217
边界球形不会默认计算,需要调用该接口指定计算边界球形,否则保持默认值 *null*。
200
218
</ p >
201
219
202
220
< h3 > [method:undefined computeTangents]()</ h3 >
203
221
< p >
204
222
计算并向此geometry中添加tangent attribute。< br />
205
- 只支持索引化的几何体对象,并且必须拥有position(位置),normal(法向)和 uv attributes。如果使用了切线空间法向贴图,最好使用[page:BufferGeometryUtils.computeMikkTSpaceTangents]中的MikkTSpace算法。
223
+ 只支持索引化的几何体对象,并且必须拥有position(位置),normal(法向)和 uv attributes。如果使用了切线空间法向贴图,最好使用 [page:BufferGeometryUtils.computeMikkTSpaceTangents] 中的MikkTSpace算法。
206
224
</ p >
207
225
208
226
< h3 > [method:undefined computeVertexNormals]()</ h3 >
209
- < p > 通过面片法向量的平均值计算每个顶点的法向量。</ p >
227
+ < p > 通过面片法向量的平均值计算每个顶点的法向量。对于索引几何体,该方法将每个顶点法线设置为共享该顶点的面的面法线的平均值。对于非索引几何体,顶点不共享,该方法将每个顶点法线设置为与面法线相同。</ p >
228
+
229
+ < h3 > [method:this copy]( [param:BufferGeometry bufferGeometry] )</ h3 >
230
+ < p > 将参数指定的 BufferGeometry 的值拷贝到当前 BufferGeometry 中。</ p >
231
+
232
+ < h3 > [method:BufferAttribute deleteAttribute]( [param:String name] )</ h3 >
233
+ < p > 删除具有指定名称的 [page:BufferAttribute attribute]。</ p >
210
234
211
235
< h3 > [method:undefined dispose]()</ h3 >
212
236
< p >
@@ -235,9 +259,6 @@ <h3>[method:undefined normalizeNormals]()</h3>
235
259
几何体中的每个法向量长度将会为 1。这样操作会更正光线在表面的效果。
236
260
</ p >
237
261
238
- < h3 > [method:BufferAttribute deleteAttribute]( [param:String name] )</ h3 >
239
- < p > 删除具有指定名称的 [page:BufferAttribute attribute]。</ p >
240
-
241
262
< h3 > [method:this rotateX] ( [param:Float radians] )</ h3 >
242
263
< p >
243
264
在 X 轴上旋转几何体。该操作一般在一次处理中完成,不会循环处理。典型的用法是通过调用 [page:Object3D.rotation] 实时旋转几何体。
@@ -258,24 +279,30 @@ <h3>[method:this scale] ( [param:Float x], [param:Float y], [param:Float z] )</h
258
279
缩放几何体。该操作一般在一次处理中完成,不会循环处理。典型的用法是通过调用 [page:Object3D.scale] 实时旋转几何体。
259
280
</ p >
260
281
261
- < h3 > [method:this setIndex] ( [param:BufferAttribute index] )</ h3 >
262
- < p > 设置缓存的 [page:.index]。</ p >
282
+ < h3 > [method:this setAttribute]( [param:String name], [param:BufferAttribute attribute] )</ h3 >
283
+ < p >
284
+ 为当前几何体设置一个 attribute 属性。在类的内部,有一个存储 [page:.attributes] 的 hashmap,
285
+ 通过该 hashmap,遍历 attributes 的速度会更快。
286
+ </ p >
263
287
264
288
< h3 > [method:undefined setDrawRange] ( [param:Integer start], [param:Integer count] )</ h3 >
265
- < p > 设置缓存的 [page:.drawRange]。详见相关属性说明 。</ p >
289
+ < p > 设置 [page:.drawRange] 属性。对于非索引 BufferGeometry,count 是要渲染的顶点数。对于索引 BufferGeometry,count 是要渲染的索引数 。</ p >
266
290
267
291
< h3 > [method:this setFromPoints] ( [param:Array points] )</ h3 >
268
- < p > 通过点队列设置该 BufferGeometry 的 attribute。</ p >
292
+ < p > 通过基于给定的 points 设置几何图形的位置属性。该数组可以保存 Vector2 或 Vector3 的实例。使用二维数据时,所有顶点的 z 坐标均设置为 0。如果该方法与现有位置属性一起使用,则顶点数据将被数组中的数据覆盖。数组的长度必须与顶点数匹配。</ p >
293
+
294
+ < h3 > [method:this setIndex] ( [param:BufferAttribute index] )</ h3 >
295
+ < p > 设置缓存的 [page:.index]。</ p >
269
296
270
297
< h3 > [method:Object toJSON]()</ h3 >
271
- < p > 返回代表该 BufferGeometry 的 JSON 对象。</ p >
298
+ < p > 返回代表该 BufferGeometry 符合 [link:https://github.com/mrdoob/three.js/wiki/JSON-Object-Scene-format-4 Object/Scene 规范] 的 JSON 对象。</ p >
272
299
273
300
< h3 > [method:BufferGeometry toNonIndexed]()</ h3 >
274
301
< p > 返回已索引的 BufferGeometry 的非索引版本。</ p >
275
302
276
303
< h3 > [method:this translate] ( [param:Float x], [param:Float y], [param:Float z] )</ h3 >
277
304
< p >
278
- 移动几何体。该操作一般在一次处理中完成,不会循环处理。典型的用法是通过调用 [page:Object3D.rotation] 实时旋转几何体 。
305
+ 移动几何体。该操作一般在一次处理中完成,不会循环处理。典型的用法是通过调用 [page:Object3D.position] 实时移动几何体 。
279
306
</ p >
280
307
281
308
< h2 > Source</ h2 >
0 commit comments