2
0

BufferAttribute.html 9.2 KB

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