forked from serjIII/threejsSDK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBufferAttribute.html
252 lines (201 loc) · 9.71 KB
/
BufferAttribute.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
<!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 class="desc">
This class stores data for an attribute (such as vertex positions, face
indices, normals, colors, UVs, and any custom attributes ) associated with
a [page:BufferGeometry], which allows for more efficient passing of data
to the GPU. See that page for details and a usage example. When working
with vector-like data, the <i>.fromBufferAttribute( attribute, index )</i>
helper methods on [page:Vector2.fromBufferAttribute Vector2],
[page:Vector3.fromBufferAttribute Vector3],
[page:Vector4.fromBufferAttribute Vector4], and
[page:Color.fromBufferAttribute Color] classes may be helpful.
</p>
<h2>Constructor</h2>
<h3>[name]( [param:TypedArray array], [param:Integer itemSize], [param:Boolean normalized] )</h3>
<p>
[page:TypedArray array] -- Must be a
[link:https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/TypedArray TypedArray]. Used to instantiate the buffer. <br />
This array should have
<code>
itemSize * numVertices
</code>
elements, where numVertices is the number of vertices in the associated
[page:BufferGemetry BufferGeometry].<br /><br />
[page:Integer itemSize] -- the number of values of the array that should
be associated with a particular vertex. For instance, if this attribute is
storing a 3-component vector (such as a position, normal, or color), then
itemSize should be 3.
<br /><br />
[page:Boolean normalized] -- (optional) Applies to integer data only.
Indicates how the underlying data in the buffer maps to the values in the
GLSL code. For instance, if [page:TypedArray array] is an instance of
UInt16Array, and [page:Boolean normalized] is true, the values `0 -
+65535` in the array data will be mapped to 0.0f - +1.0f in the GLSL
attribute. An Int16Array (signed) would map from -32768 - +32767 to -1.0f
- +1.0f. If [page:Boolean normalized] is false, the values will be
converted to floats unmodified, i.e. 32767 becomes 32767.0f.
</p>
<h2>Properties</h2>
<h3>[property:TypedArray array]</h3>
<p>The [page:TypedArray array] holding data stored in the buffer.</p>
<h3>[property:Integer count]</h3>
<p>
Stores the [page:BufferAttribute.array array]'s length divided by the
[page:BufferAttribute.itemSize itemSize].<br /><br />
If the buffer is storing a 3-component vector (such as a position, normal,
or color), then this will count the number of such vectors stored.
</p>
<h3>[property:Number gpuType]</h3>
<p>
Configures the bound GPU type for use in shaders. Either [page:BufferAttribute THREE.FloatType] or [page:BufferAttribute THREE.IntType], default is [page:BufferAttribute THREE.FloatType].
Note: this only has an effect for integer arrays and is not configurable for float arrays. For lower precision float types, see [page:BufferAttributeTypes THREE.Float16BufferAttribute].
</p>
<h3>[property:Boolean isBufferAttribute]</h3>
<p>Read-only flag to check if a given object is of type [name].</p>
<h3>[property:Integer itemSize]</h3>
<p>
The length of vectors that are being stored in the
[page:BufferAttribute.array array].
</p>
<h3>[property:String name]</h3>
<p>Optional name for this attribute instance. Default is an empty string.</p>
<h3>[property:Boolean needsUpdate]</h3>
<p>
Flag to indicate that this attribute has changed and should be re-sent to
the GPU. Set this to true when you modify the value of the array.<br /><br />
Setting this to true also increments the [page:BufferAttribute.version version].
</p>
<h3>[property:Boolean normalized]</h3>
<p>
Indicates how the underlying data in the buffer maps to the values in the
GLSL shader code. See the constructor above for details.
</p>
<h3>[property:Function onUploadCallback]</h3>
<p>
A callback function that is executed after the Renderer has transferred
the attribute array data to the GPU.
</p>
<h3>[property:Object updateRange]</h3>
<p>
Object containing:<br />
[page:Integer offset]: Default is `0`. Position at which to start
update.<br />
[page:Integer count]: Default is `-1`, which means don't use update
ranges. <br /><br />
This can be used to only update some components of stored vectors (for
example, just the component related to color).
</p>
<h3>[property:Usage usage]</h3>
<p>
Defines the intended usage pattern of the data store for optimization
purposes. Corresponds to the `usage` parameter of
[link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/bufferData WebGLRenderingContext.bufferData](). Default is [page:BufferAttributeUsage StaticDrawUsage]. See usage [page:BufferAttributeUsage constants] for all
possible values. <br /><br />
Note: After the initial use of a buffer, its usage cannot be changed.
Instead, instantiate a new one and set the desired usage before the next
render.
</p>
<h3>[property:Integer version]</h3>
<p>
A version number, incremented every time the
[page:BufferAttribute.needsUpdate needsUpdate] property is set to true.
</p>
<h2>Methods</h2>
<h3>[method:this applyMatrix3]( [param:Matrix3 m] )</h3>
<p>
Applies matrix [page:Matrix3 m] to every Vector3 element of this
BufferAttribute.
</p>
<h3>[method:this applyMatrix4]( [param:Matrix4 m] )</h3>
<p>
Applies matrix [page:Matrix4 m] to every Vector3 element of this
BufferAttribute.
</p>
<h3>[method:this applyNormalMatrix]( [param:Matrix3 m] )</h3>
<p>
Applies normal matrix [page:Matrix3 m] to every Vector3 element of this
BufferAttribute.
</p>
<h3>[method:this transformDirection]( [param:Matrix4 m] )</h3>
<p>
Applies matrix [page:Matrix4 m] to every Vector3 element of this
BufferAttribute, interpreting the elements as a direction vectors.
</p>
<h3>[method:BufferAttribute clone]()</h3>
<p>Return a copy of this bufferAttribute.</p>
<h3>[method:this copy]( [param:BufferAttribute bufferAttribute] )</h3>
<p>Copies another BufferAttribute to this BufferAttribute.</p>
<h3>[method:this copyArray]( array )</h3>
<p>
Copy the array given here (which can be a normal array or TypedArray) into
[page:BufferAttribute.array array].<br /><br />
See
[link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/set TypedArray.set] for notes on requirements if copying a TypedArray.
</p>
<h3>[method:this copyAt] ( [param:Integer index1], [param:BufferAttribute bufferAttribute], [param:Integer index2] )</h3>
<p>Copy a vector from bufferAttribute[index2] to [page:BufferAttribute.array array][index1].</p>
<h3>[method:Number getX]( [param:Integer index] )</h3>
<p>Returns the x component of the vector at the given index.</p>
<h3>[method:Number getY]( [param:Integer index] )</h3>
<p>Returns the y component of the vector at the given index.</p>
<h3>[method:Number getZ]( [param:Integer index] )</h3>
<p>Returns the z component of the vector at the given index.</p>
<h3>[method:Number getW]( [param:Integer index] )</h3>
<p>Returns the w component of the vector at the given index.</p>
<h3>[method:this onUpload]( [param:Function callback] )</h3>
<p>
Sets the value of the onUploadCallback property.<br /><br />
In the [example:webgl_buffergeometry WebGL / Buffergeometry] this is used
to free memory after the buffer has been transferred to the GPU.
</p>
<h3>[method:this set] ( [param:Array value], [param:Integer offset] )</h3>
<p>
value -- an [page:Array] or [page:TypedArray] from which to copy values.
<br />
offset -- (optional) index of the [page:BufferAttribute.array array] at
which to start copying.<br /><br />
Calls
[link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/set TypedArray.set]( [page:Array value], [page:Integer offset] ) on the
[page:BufferAttribute.array array].<br /><br />
In particular, see that page for requirements on [page:Array value] being
a [page:TypedArray].
</p>
<h3>[method:this setUsage] ( [param:Usage value] )</h3>
<p>
Set [page:BufferAttribute.usage usage] to value. See usage
[page:BufferAttributeUsage constants] for all possible input values.
<br /><br />
Note: After the initial use of a buffer, its usage cannot be changed.
Instead, instantiate a new one and set the desired usage before the next
render.
</p>
<h3>[method:this setX]( [param:Integer index], [param:Float x] )</h3>
<p>Sets the x component of the vector at the given index.</p>
<h3>[method:this setY]( [param:Integer index], [param:Float y] )</h3>
<p>Sets the y component of the vector at the given index.</p>
<h3>[method:this setZ]( [param:Integer index], [param:Float z] )</h3>
<p>Sets the z component of the vector at the given index.</p>
<h3>[method:this setW]( [param:Integer index], [param:Float w] )</h3>
<p>Sets the w component of the vector at the given index.</p>
<h3>[method:this setXY]( [param:Integer index], [param:Float x], [param:Float y] )</h3>
<p>Sets the x and y components of the vector at the given index.</p>
<h3>[method:this setXYZ]( [param:Integer index], [param:Float x], [param:Float y], [param:Float z] )</h3>
<p>Sets the x, y and z components of the vector at the given index.</p>
<h3>[method:this setXYZW]( [param:Integer index], [param:Float x], [param:Float y], [param:Float z], [param:Float w] )
</h3>
<p>Sets the x, y, z and w components of the vector at the given index.</p>
<h2>Source</h2>
<p>
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
</p>
</body>
</html>