BufferAttribute.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. Represents the number of items this buffer attribute stores. It is internally computed by dividing the [page:BufferAttribute.array array]'s length by the
  53. [page:BufferAttribute.itemSize itemSize]. Read-only property.
  54. </p>
  55. <h3>[property:Number gpuType]</h3>
  56. <p>
  57. 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].
  58. 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].
  59. </p>
  60. <h3>[property:Boolean isBufferAttribute]</h3>
  61. <p>Read-only flag to check if a given object is of type [name].</p>
  62. <h3>[property:Integer itemSize]</h3>
  63. <p>
  64. The length of vectors that are being stored in the
  65. [page:BufferAttribute.array array].
  66. </p>
  67. <h3>[property:String name]</h3>
  68. <p>Optional name for this attribute instance. Default is an empty string.</p>
  69. <h3>[property:Boolean needsUpdate]</h3>
  70. <p>
  71. Flag to indicate that this attribute has changed and should be re-sent to
  72. the GPU. Set this to true when you modify the value of the array.<br /><br />
  73. Setting this to true also increments the [page:BufferAttribute.version version].
  74. </p>
  75. <h3>[property:Boolean normalized]</h3>
  76. <p>
  77. Indicates how the underlying data in the buffer maps to the values in the
  78. GLSL shader code. See the constructor above for details.
  79. </p>
  80. <h3>[property:Function onUploadCallback]</h3>
  81. <p>
  82. A callback function that is executed after the Renderer has transferred
  83. the attribute array data to the GPU.
  84. </p>
  85. <h3>[property:Object updateRanges]</h3>
  86. <p>
  87. Array of objects containing:<br />
  88. [page:Integer start]: Position at which to start
  89. update.<br />
  90. [page:Integer count]: The number of components to update. <br /><br />
  91. This can be used to only update some components of stored vectors (for
  92. example, just the component related to color). Use the [page:BufferAttribute.addUpdateRange addUpdateRange]
  93. function to add ranges to this array.
  94. </p>
  95. <h3>[property:Usage usage]</h3>
  96. <p>
  97. Defines the intended usage pattern of the data store for optimization
  98. purposes. Corresponds to the `usage` parameter of
  99. [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
  100. possible values. <br /><br />
  101. Note: After the initial use of a buffer, its usage cannot be changed.
  102. Instead, instantiate a new one and set the desired usage before the next
  103. render.
  104. </p>
  105. <h3>[property:Integer version]</h3>
  106. <p>
  107. A version number, incremented every time the
  108. [page:BufferAttribute.needsUpdate needsUpdate] property is set to true.
  109. </p>
  110. <h2>Methods</h2>
  111. <h3>[method:this applyMatrix3]( [param:Matrix3 m] )</h3>
  112. <p>
  113. Applies matrix [page:Matrix3 m] to every Vector3 element of this
  114. BufferAttribute.
  115. </p>
  116. <h3>[method:this applyMatrix4]( [param:Matrix4 m] )</h3>
  117. <p>
  118. Applies matrix [page:Matrix4 m] to every Vector3 element of this
  119. BufferAttribute.
  120. </p>
  121. <h3>[method:this applyNormalMatrix]( [param:Matrix3 m] )</h3>
  122. <p>
  123. Applies normal matrix [page:Matrix3 m] to every Vector3 element of this
  124. BufferAttribute.
  125. </p>
  126. <h3>[method:this transformDirection]( [param:Matrix4 m] )</h3>
  127. <p>
  128. Applies matrix [page:Matrix4 m] to every Vector3 element of this
  129. BufferAttribute, interpreting the elements as a direction vectors.
  130. </p>
  131. <h3>[method:this addUpdateRange]( [param:Integer start], [param:Integer count] )</h3>
  132. <p>
  133. Adds a range of data in the data array to be updated on the GPU. Adds an
  134. object describing the range to the [page:BufferAttribute.updateRanges updateRanges]
  135. array.
  136. </p>
  137. <h3>[method:this clearUpdateRanges]()</h3>
  138. <p>
  139. Clears the [page:BufferAttribute.updateRanges updateRanges] array.
  140. </p>
  141. <h3>[method:BufferAttribute clone]()</h3>
  142. <p>Return a copy of this bufferAttribute.</p>
  143. <h3>[method:this copy]( [param:BufferAttribute bufferAttribute] )</h3>
  144. <p>Copies another BufferAttribute to this BufferAttribute.</p>
  145. <h3>[method:this copyArray]( array )</h3>
  146. <p>
  147. Copy the array given here (which can be a normal array or TypedArray) into
  148. [page:BufferAttribute.array array].<br /><br />
  149. See
  150. [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.
  151. </p>
  152. <h3>[method:this copyAt] ( [param:Integer index1], [param:BufferAttribute bufferAttribute], [param:Integer index2] )</h3>
  153. <p>Copy a vector from bufferAttribute[index2] to [page:BufferAttribute.array array][index1].</p>
  154. <h3>[method:Number getComponent]( [param:Integer index], [param:Integer component] ) </h3>
  155. <p>Returns the given component of the vector at the given index.</p>
  156. <h3>[method:Number getX]( [param:Integer index] )</h3>
  157. <p>Returns the x component of the vector at the given index.</p>
  158. <h3>[method:Number getY]( [param:Integer index] )</h3>
  159. <p>Returns the y component of the vector at the given index.</p>
  160. <h3>[method:Number getZ]( [param:Integer index] )</h3>
  161. <p>Returns the z component of the vector at the given index.</p>
  162. <h3>[method:Number getW]( [param:Integer index] )</h3>
  163. <p>Returns the w component of the vector at the given index.</p>
  164. <h3>[method:this onUpload]( [param:Function callback] )</h3>
  165. <p>
  166. Sets the value of the onUploadCallback property.<br /><br />
  167. In the [example:webgl_buffergeometry WebGL / Buffergeometry] this is used
  168. to free memory after the buffer has been transferred to the GPU.
  169. </p>
  170. <h3>[method:this set] ( [param:Array value], [param:Integer offset] )</h3>
  171. <p>
  172. value -- an [page:Array] or [page:TypedArray] from which to copy values.
  173. <br />
  174. offset -- (optional) index of the [page:BufferAttribute.array array] at
  175. which to start copying.<br /><br />
  176. Calls
  177. [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
  178. [page:BufferAttribute.array array].<br /><br />
  179. In particular, see that page for requirements on [page:Array value] being
  180. a [page:TypedArray].
  181. </p>
  182. <h3>[method:this setUsage] ( [param:Usage value] )</h3>
  183. <p>
  184. Set [page:BufferAttribute.usage usage] to value. See usage
  185. [page:BufferAttributeUsage constants] for all possible input values.
  186. <br /><br />
  187. Note: After the initial use of a buffer, its usage cannot be changed.
  188. Instead, instantiate a new one and set the desired usage before the next
  189. render.
  190. </p>
  191. <h3>[method:Number setComponent]( [param:Integer index], [param:Integer component], [param:Float value] ) </h3>
  192. <p>Sets the given component of the vector at the given index.</p>
  193. <h3>[method:this setX]( [param:Integer index], [param:Float x] )</h3>
  194. <p>Sets the x component of the vector at the given index.</p>
  195. <h3>[method:this setY]( [param:Integer index], [param:Float y] )</h3>
  196. <p>Sets the y component of the vector at the given index.</p>
  197. <h3>[method:this setZ]( [param:Integer index], [param:Float z] )</h3>
  198. <p>Sets the z component of the vector at the given index.</p>
  199. <h3>[method:this setW]( [param:Integer index], [param:Float w] )</h3>
  200. <p>Sets the w component of the vector at the given index.</p>
  201. <h3>[method:this setXY]( [param:Integer index], [param:Float x], [param:Float y] )</h3>
  202. <p>Sets the x and y components of the vector at the given index.</p>
  203. <h3>[method:this setXYZ]( [param:Integer index], [param:Float x], [param:Float y], [param:Float z] )</h3>
  204. <p>Sets the x, y and z components of the vector at the given index.</p>
  205. <h3>[method:this setXYZW]( [param:Integer index], [param:Float x], [param:Float y], [param:Float z], [param:Float w] )
  206. </h3>
  207. <p>Sets the x, y, z and w components of the vector at the given index.</p>
  208. <h2>Source</h2>
  209. <p>
  210. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  211. </p>
  212. </body>
  213. </html>