forked from serjIII/threejsSDK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBufferGeometry.html
366 lines (298 loc) · 12.5 KB
/
BufferGeometry.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<base href="../../../" />
<script src="page.js"></script>
<link type="text/css" rel="stylesheet" href="page.css" />
</head>
<body>
<h1>[name]</h1>
<p>
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.
</p>
<p>
To read and edit data in BufferGeometry attributes, see
[page:BufferAttribute] documentation.
</p>
<h2>Code Example</h2>
<code>
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 );
</code>
<h2>Code Example (Index)</h2>
<code>
const geometry = new THREE.BufferGeometry();
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
] );
const indices = [
0, 1, 2,
2, 3, 0,
];
geometry.setIndex( indices );
geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
const material = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
const mesh = new THREE.Mesh( geometry, material );
</code>
<h2>Examples</h2>
<p>
[example:webgl_buffergeometry Mesh with non-indexed faces]<br />
[example:webgl_buffergeometry_indexed Mesh with indexed faces]<br />
[example:webgl_buffergeometry_lines Lines]<br />
[example:webgl_buffergeometry_lines_indexed Indexed Lines]<br />
[example:webgl_buffergeometry_custom_attributes_particles Particles]<br />
[example:webgl_buffergeometry_rawshader Raw Shaders]
</p>
<h2>Constructor</h2>
<h3>[name]()</h3>
<div>
This creates a new [name]. It also sets several properties to a default
value.
</div>
<h2>Properties</h2>
<h3>[property:Object attributes]</h3>
<p>
This hashmap has as id the name of the attribute to be set and as value
the [page:BufferAttribute buffer] to set it to. Rather than accessing this
property directly, use [page:.setAttribute] and [page:.getAttribute] to
access attributes of this geometry.
</p>
<h3>[property:Box3 boundingBox]</h3>
<p>
Bounding box for the bufferGeometry, which can be calculated with
[page:.computeBoundingBox](). Default is `null`.
</p>
<h3>[property:Sphere boundingSphere]</h3>
<p>
Bounding sphere for the bufferGeometry, which can be calculated with
[page:.computeBoundingSphere](). Default is `null`.
</p>
<h3>[property:Object drawRange]</h3>
<p>
Determines the part of the geometry to render. This should not be set
directly, instead use [page:.setDrawRange]. Default is
<code>
{ start: 0, count: Infinity }
</code>
For non-indexed BufferGeometry, count is the number of vertices to render.
For indexed BufferGeometry, count is the number of indices to render.
</p>
<h3>[property:Array groups]</h3>
<p>
Split the geometry into groups, each of which will be rendered in a
separate WebGL draw call. This allows an array of materials to be used
with the geometry.<br /><br />
Each group is an object of the form:
<code>
{ start: Integer, count: Integer, materialIndex: Integer }
</code>
where start specifies the first element in this draw call – the first
vertex for non-indexed geometry, otherwise the first triangle index. Count
specifies how many vertices (or indices) are included, and materialIndex
specifies the material array index to use.<br /><br />
Use [page:.addGroup] to add groups, rather than modifying this array
directly.<br /><br />
Every vertex and index must belong to exactly one group — groups must not
share vertices or indices, and must not leave vertices or indices unused.
</p>
<!-- Note: groups used to be called drawCalls
<h3>[property:Array drawcalls]</h3>
<p>
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 [page:Material shader]. This may be necessary if,
for instance, you have more than 65535 vertices in your object.
</p> -->
<h3>[property:Integer id]</h3>
<p>Unique number for this bufferGeometry instance.</p>
<h3>[property:BufferAttribute index]</h3>
<p>
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 the index of
each vertex for each triangular face. If this attribute is not set, the
[page:WebGLRenderer renderer] assumes that each three contiguous positions
represent a single triangle. Default is `null`.
</p>
<h3>[property:Boolean isBufferGeometry]</h3>
<p>Read-only flag to check if a given object is of type [name].</p>
<h3>[property:Object morphAttributes]</h3>
<p>
Hashmap of [page:BufferAttribute]s holding details of the geometry's morph
targets.<br />
Note: Once the geometry has been rendered, the morph attribute data cannot
be changed. You will have to call [page:.dispose](), and create a new
instance of [name].
</p>
<h3>[property:Boolean morphTargetsRelative]</h3>
<p>
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`.
</p>
<h3>[property:String name]</h3>
<p>
Optional name for this bufferGeometry instance. Default is an empty
string.
</p>
<h3>[property:Object userData]</h3>
<p>
An object that can be used to store custom data about the BufferGeometry.
It should not hold references to functions as these will not be cloned.
</p>
<h3>[property:String uuid]</h3>
<p>
[link:http://en.wikipedia.org/wiki/Universally_unique_identifier UUID] of
this object instance. This gets automatically assigned and shouldn't be
edited.
</p>
<h2>Methods</h2>
<p>
[page:EventDispatcher EventDispatcher] methods are available on this
class.
</p>
<h3>[method:undefined addGroup]( [param:Integer start], [param:Integer count], [param:Integer materialIndex] )</h3>
<p>
Adds a group to this geometry; see the [page:BufferGeometry.groups groups]
property for details.
</p>
<h3>[method:this applyMatrix4]( [param:Matrix4 matrix] )</h3>
<p>Applies the matrix transform to the geometry.</p>
<h3>[method:this applyQuaternion]( [param:Quaternion quaternion] )</h3>
<p>Applies the rotation represented by the quaternion to the geometry.</p>
<h3>[method:this center] ()</h3>
<p>Center the geometry based on the bounding box.</p>
<h3>[method:undefined clearGroups]( )</h3>
<p>Clears all groups.</p>
<h3>[method:BufferGeometry clone]()</h3>
<p>Creates a clone of this BufferGeometry.</p>
<h3>[method:undefined computeBoundingBox]()</h3>
<p>
Computes bounding box of the geometry, updating [page:.boundingBox]
attribute.<br />
Bounding boxes aren't computed by default. They need to be explicitly
computed, otherwise they are `null`.
</p>
<h3>[method:undefined computeBoundingSphere]()</h3>
<p>
Computes bounding sphere of the geometry, updating [page:.boundingSphere]
attribute.<br />
Bounding spheres aren't computed by default. They need to be explicitly
computed, otherwise they are `null`.
</p>
<h3>[method:undefined computeTangents]()</h3>
<p>
Calculates and adds a tangent attribute to this geometry.<br />
The computation is only supported for indexed geometries and if position,
normal, and uv attributes are defined. When using a tangent space normal
map, prefer the MikkTSpace algorithm provided by
[page:BufferGeometryUtils.computeMikkTSpaceTangents] instead.
</p>
<h3>[method:undefined computeVertexNormals]()</h3>
<p>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-indexed geometries, vertices are not shared, and the method sets each vertex normal to be the same as the face normal.</p>
<h3>[method:this copy]( [param:BufferGeometry bufferGeometry] )</h3>
<p>Copies another BufferGeometry to this BufferGeometry.</p>
<h3>[method:BufferAttribute deleteAttribute]( [param:String name] )</h3>
<p>Deletes the [page:BufferAttribute attribute] with the specified name.</p>
<h3>[method:undefined dispose]()</h3>
<p>
Frees the GPU-related resources allocated by this instance. Call this
method whenever this instance is no longer used in your app.
</p>
<h3>[method:BufferAttribute getAttribute]( [param:String name] )</h3>
<p>Returns the [page:BufferAttribute attribute] with the specified name.</p>
<h3>[method:BufferAttribute getIndex] ()</h3>
<p>Return the [page:.index] buffer.</p>
<h3>[method:Boolean hasAttribute]( [param:String name] )</h3>
<p>Returns `true` if the attribute with the specified name exists.</p>
<h3>[method:this lookAt] ( [param:Vector3 vector] )</h3>
<p>
vector - A world vector to look at.<br /><br />
Rotates the geometry to face a point in space. This is typically done as a
one time operation, and not during a loop. Use [page:Object3D.lookAt] for
typical real-time mesh usage.
</p>
<h3>[method:undefined normalizeNormals]()</h3>
<p>
Every normal vector in a geometry will have a magnitude of `1`. This will
correct lighting on the geometry surfaces.
</p>
<h3>[method:this rotateX] ( [param:Float radians] )</h3>
<p>
Rotate the geometry about the X axis. This is typically done as a one time
operation, and not during a loop. Use [page:Object3D.rotation] for typical
real-time mesh rotation.
</p>
<h3>[method:this rotateY] ( [param:Float radians] )</h3>
<p>
Rotate the geometry about the Y axis. This is typically done as a one time
operation, and not during a loop. Use [page:Object3D.rotation] for typical
real-time mesh rotation.
</p>
<h3>[method:this rotateZ] ( [param:Float radians] )</h3>
<p>
Rotate the geometry about the Z axis. This is typically done as a one time
operation, and not during a loop. Use [page:Object3D.rotation] for typical
real-time mesh rotation.
</p>
<h3>[method:this scale] ( [param:Float x], [param:Float y], [param:Float z] )</h3>
<p>
Scale the geometry data. This is typically done as a one time operation,
and not during a loop. Use [page:Object3D.scale] for typical real-time
mesh scaling.
</p>
<h3>[method:this setAttribute]( [param:String name], [param:BufferAttribute attribute] )</h3>
<p>
Sets an attribute to this geometry. Use this rather than the attributes
property, because an internal hashmap of [page:.attributes] is maintained
to speed up iterating over attributes.
</p>
<h3>[method:undefined setDrawRange] ( [param:Integer start], [param:Integer count] )</h3>
<p>
Set the [page:.drawRange] property. For non-indexed BufferGeometry, count
is the number of vertices to render. For indexed BufferGeometry, count is
the number of indices to render.
</p>
<h3>[method:this setFromPoints] ( [param:Array points] )</h3>
<p>Sets the attributes for this BufferGeometry from an array of points.</p>
<h3>[method:this setIndex] ( [param:BufferAttribute index] )</h3>
<p>Set the [page:.index] buffer.</p>
<h3>[method:Object toJSON]()</h3>
<p>
Convert the buffer geometry to three.js
[link:https://github.com/mrdoob/three.js/wiki/JSON-Object-Scene-format-4 JSON Object/Scene format].
</p>
<h3>[method:BufferGeometry toNonIndexed]()</h3>
<p>Return a non-index version of an indexed BufferGeometry.</p>
<h3>[method:this translate] ( [param:Float x], [param:Float y], [param:Float z] )</h3>
<p>
Translate the geometry. This is typically done as a one time operation,
and not during a loop. Use [page:Object3D.position] for typical real-time
mesh translation.
</p>
<h2>Source</h2>
<p>
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
</p>
</body>
</html>