BufferAttribute.html 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="page.css" />
  8. </head>
  9. <body>
  10. <h1>[name]</h1>
  11. <p class="desc">
  12. This class stores data for an attribute (such as vertex positions, face
  13. indices, normals, colors, UVs, and any custom attributes ) associated with
  14. a [page:BufferGeometry], which allows for more efficient passing of data
  15. to the GPU. See that page for details and a usage example. When working
  16. with vector-like data, the <i>.fromBufferAttribute( attribute, index )</i>
  17. helper methods on [page:Vector2.fromBufferAttribute Vector2],
  18. [page:Vector3.fromBufferAttribute Vector3],
  19. [page:Vector4.fromBufferAttribute Vector4], and
  20. [page:Color.fromBufferAttribute Color] classes may be helpful.
  21. </p>
  22. <h2>Constructor</h2>
  23. <h3>[name]( [param:TypedArray array], [param:Integer itemSize], [param:Boolean normalized] )</h3>
  24. <p>
  25. [page:TypedArray array] -- Must be a
  26. [link:https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/TypedArray TypedArray]. Used to instantiate the buffer. <br />
  27. This array should have
  28. <code>
  29. itemSize * numVertices
  30. </code>
  31. elements, where numVertices is the number of vertices in the associated
  32. [page:BufferGemetry BufferGeometry].<br /><br />
  33. [page:Integer itemSize] -- the number of values of the array that should
  34. be associated with a particular vertex. For instance, if this attribute is
  35. storing a 3-component vector (such as a position, normal, or color), then
  36. itemSize should be 3.
  37. <br /><br />
  38. [page:Boolean normalized] -- (optional) Applies to integer data only.
  39. Indicates how the underlying data in the buffer maps to the values in the
  40. GLSL code. For instance, if [page:TypedArray array] is an instance of
  41. UInt16Array, and [page:Boolean normalized] is true, the values `0 -
  42. +65535` in the array data will be mapped to 0.0f - +1.0f in the GLSL
  43. attribute. An Int16Array (signed) would map from -32768 - +32767 to -1.0f
  44. - +1.0f. If [page:Boolean normalized] is false, the values will be
  45. converted to floats unmodified, i.e. 32767 becomes 32767.0f.
  46. </p>
  47. <h2>Properties</h2>
  48. <h3>[property:TypedArray array]</h3>
  49. <p>The [page:TypedArray array] holding data stored in the buffer.</p>
  50. <h3>[property:Integer count]</h3>
  51. <p>
  52. Stores the [page:BufferAttribute.array array]'s length divided by the
  53. [page:BufferAttribute.itemSize itemSize].<br /><br />
  54. If the buffer is storing a 3-component vector (such as a position, normal,
  55. or color), then this will count the number of such vectors stored.
  56. </p>
  57. <h3>[property:Boolean isBufferAttribute]</h3>
  58. <p>Read-only flag to check if a given object is of type [name].</p>
  59. <h3>[property:Integer itemSize]</h3>
  60. <p>
  61. The length of vectors that are being stored in the
  62. [page:BufferAttribute.array array].
  63. </p>
  64. <h3>[property:String name]</h3>
  65. <p>Optional name for this attribute instance. Default is an empty string.</p>
  66. <h3>[property:Boolean needsUpdate]</h3>
  67. <p>
  68. Flag to indicate that this attribute has changed and should be re-sent to
  69. the GPU. Set this to true when you modify the value of the array.<br /><br />
  70. Setting this to true also increments the [page:BufferAttribute.version version].
  71. </p>
  72. <h3>[property:Boolean normalized]</h3>
  73. <p>
  74. Indicates how the underlying data in the buffer maps to the values in the
  75. GLSL shader code. See the constructor above for details.
  76. </p>
  77. <h3>[property:Function onUploadCallback]</h3>
  78. <p>
  79. A callback function that is executed after the Renderer has transferred
  80. the attribute array data to the GPU.
  81. </p>
  82. <h3>[property:Object updateRange]</h3>
  83. <p>
  84. Object containing:<br />
  85. [page:Integer offset]: Default is `0`. Position at which to start
  86. update.<br />
  87. [page:Integer count]: Default is `-1`, which means don't use update
  88. ranges. <br /><br />
  89. This can be used to only update some components of stored vectors (for
  90. example, just the component related to color).
  91. </p>
  92. <h3>[property:Usage usage]</h3>
  93. <p>
  94. Defines the intended usage pattern of the data store for optimization
  95. purposes. Corresponds to the `usage` parameter of
  96. [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
  97. possible values. <br /><br />
  98. Note: After the initial use of a buffer, its usage cannot be changed.
  99. Instead, instantiate a new one and set the desired usage before the next
  100. render.
  101. </p>
  102. <h3>[property:Integer version]</h3>
  103. <p>
  104. A version number, incremented every time the
  105. [page:BufferAttribute.needsUpdate needsUpdate] property is set to true.
  106. </p>
  107. <h2>Methods</h2>
  108. <h3>[method:this applyMatrix3]( [param:Matrix3 m] )</h3>
  109. <p>
  110. Applies matrix [page:Matrix3 m] to every Vector3 element of this
  111. BufferAttribute.
  112. </p>
  113. <h3>[method:this applyMatrix4]( [param:Matrix4 m] )</h3>
  114. <p>
  115. Applies matrix [page:Matrix4 m] to every Vector3 element of this
  116. BufferAttribute.
  117. </p>
  118. <h3>[method:this applyNormalMatrix]( [param:Matrix3 m] )</h3>
  119. <p>
  120. Applies normal matrix [page:Matrix3 m] to every Vector3 element of this
  121. BufferAttribute.
  122. </p>
  123. <h3>[method:this transformDirection]( [param:Matrix4 m] )</h3>
  124. <p>
  125. Applies matrix [page:Matrix4 m] to every Vector3 element of this
  126. BufferAttribute, interpreting the elements as a direction vectors.
  127. </p>
  128. <h3>[method:BufferAttribute clone]()</h3>
  129. <p>Return a copy of this bufferAttribute.</p>
  130. <h3>[method:this copy]( [param:BufferAttribute bufferAttribute] )</h3>
  131. <p>Copies another BufferAttribute to this BufferAttribute.</p>
  132. <h3>[method:this copyArray]( array )</h3>
  133. <p>
  134. Copy the array given here (which can be a normal array or TypedArray) into
  135. [page:BufferAttribute.array array].<br /><br />
  136. See
  137. [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.
  138. </p>
  139. <h3>[method:this copyAt] ( [param:Integer index1], [param:BufferAttribute bufferAttribute], [param:Integer index2] )</h3>
  140. <p>Copy a vector from bufferAttribute[index2] to [page:BufferAttribute.array array][index1].</p>
  141. <h3>[method:Number getX]( [param:Integer index] )</h3>
  142. <p>Returns the x component of the vector at the given index.</p>
  143. <h3>[method:Number getY]( [param:Integer index] )</h3>
  144. <p>Returns the y component of the vector at the given index.</p>
  145. <h3>[method:Number getZ]( [param:Integer index] )</h3>
  146. <p>Returns the z component of the vector at the given index.</p>
  147. <h3>[method:Number getW]( [param:Integer index] )</h3>
  148. <p>Returns the w component of the vector at the given index.</p>
  149. <h3>[method:this onUpload]( [param:Function callback] )</h3>
  150. <p>
  151. Sets the value of the onUploadCallback property.<br /><br />
  152. In the [example:webgl_buffergeometry WebGL / Buffergeometry] this is used
  153. to free memory after the buffer has been transferred to the GPU.
  154. </p>
  155. <h3>[method:this set] ( [param:Array value], [param:Integer offset] )</h3>
  156. <p>
  157. value -- an [page:Array] or [page:TypedArray] from which to copy values.
  158. <br />
  159. offset -- (optional) index of the [page:BufferAttribute.array array] at
  160. which to start copying.<br /><br />
  161. Calls
  162. [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
  163. [page:BufferAttribute.array array].<br /><br />
  164. In particular, see that page for requirements on [page:Array value] being
  165. a [page:TypedArray].
  166. </p>
  167. <h3>[method:this setUsage] ( [param:Usage value] )</h3>
  168. <p>
  169. Set [page:BufferAttribute.usage usage] to value. See usage
  170. [page:BufferAttributeUsage constants] for all possible input values.
  171. <br /><br />
  172. Note: After the initial use of a buffer, its usage cannot be changed.
  173. Instead, instantiate a new one and set the desired usage before the next
  174. render.
  175. </p>
  176. <h3>[method:this setX]( [param:Integer index], [param:Float x] )</h3>
  177. <p>Sets the x component of the vector at the given index.</p>
  178. <h3>[method:this setY]( [param:Integer index], [param:Float y] )</h3>
  179. <p>Sets the y component of the vector at the given index.</p>
  180. <h3>[method:this setZ]( [param:Integer index], [param:Float z] )</h3>
  181. <p>Sets the z component of the vector at the given index.</p>
  182. <h3>[method:this setW]( [param:Integer index], [param:Float w] )</h3>
  183. <p>Sets the w component of the vector at the given index.</p>
  184. <h3>[method:this setXY]( [param:Integer index], [param:Float x], [param:Float y] )</h3>
  185. <p>Sets the x and y components of the vector at the given index.</p>
  186. <h3>[method:this setXYZ]( [param:Integer index], [param:Float x], [param:Float y], [param:Float z] )</h3>
  187. <p>Sets the x, y and z components of the vector at the given index.</p>
  188. <h3>[method:this setXYZW]( [param:Integer index], [param:Float x], [param:Float y], [param:Float z], [param:Float w] )
  189. </h3>
  190. <p>Sets the x, y, z and w components of the vector at the given index.</p>
  191. <h2>Source</h2>
  192. <p>
  193. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  194. </p>
  195. </body>
  196. </html>