BufferAttribute.html 9.3 KB

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