BufferAttribute.html 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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 updateRange]</h3>
  86. <p>
  87. Object containing:<br />
  88. [page:Integer offset]: Default is `0`. Position at which to start
  89. update.<br />
  90. [page:Integer count]: Default is `-1`, which means don't use update
  91. ranges. <br /><br />
  92. This can be used to only update some components of stored vectors (for
  93. example, just the component related to color).
  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:BufferAttribute clone]()</h3>
  132. <p>Return a copy of this bufferAttribute.</p>
  133. <h3>[method:this copy]( [param:BufferAttribute bufferAttribute] )</h3>
  134. <p>Copies another BufferAttribute to this BufferAttribute.</p>
  135. <h3>[method:this copyArray]( array )</h3>
  136. <p>
  137. Copy the array given here (which can be a normal array or TypedArray) into
  138. [page:BufferAttribute.array array].<br /><br />
  139. See
  140. [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.
  141. </p>
  142. <h3>[method:this copyAt] ( [param:Integer index1], [param:BufferAttribute bufferAttribute], [param:Integer index2] )</h3>
  143. <p>Copy a vector from bufferAttribute[index2] to [page:BufferAttribute.array array][index1].</p>
  144. <h3>[method:Number getComponent]( [param:Integer index], [param:Integer component] ) </h3>
  145. <p>Returns the given component of the vector at the given index.</p>
  146. <h3>[method:Number getX]( [param:Integer index] )</h3>
  147. <p>Returns the x component of the vector at the given index.</p>
  148. <h3>[method:Number getY]( [param:Integer index] )</h3>
  149. <p>Returns the y component of the vector at the given index.</p>
  150. <h3>[method:Number getZ]( [param:Integer index] )</h3>
  151. <p>Returns the z component of the vector at the given index.</p>
  152. <h3>[method:Number getW]( [param:Integer index] )</h3>
  153. <p>Returns the w component of the vector at the given index.</p>
  154. <h3>[method:this onUpload]( [param:Function callback] )</h3>
  155. <p>
  156. Sets the value of the onUploadCallback property.<br /><br />
  157. In the [example:webgl_buffergeometry WebGL / Buffergeometry] this is used
  158. to free memory after the buffer has been transferred to the GPU.
  159. </p>
  160. <h3>[method:this set] ( [param:Array value], [param:Integer offset] )</h3>
  161. <p>
  162. value -- an [page:Array] or [page:TypedArray] from which to copy values.
  163. <br />
  164. offset -- (optional) index of the [page:BufferAttribute.array array] at
  165. which to start copying.<br /><br />
  166. Calls
  167. [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
  168. [page:BufferAttribute.array array].<br /><br />
  169. In particular, see that page for requirements on [page:Array value] being
  170. a [page:TypedArray].
  171. </p>
  172. <h3>[method:this setUsage] ( [param:Usage value] )</h3>
  173. <p>
  174. Set [page:BufferAttribute.usage usage] to value. See usage
  175. [page:BufferAttributeUsage constants] for all possible input values.
  176. <br /><br />
  177. Note: After the initial use of a buffer, its usage cannot be changed.
  178. Instead, instantiate a new one and set the desired usage before the next
  179. render.
  180. </p>
  181. <h3>[method:Number setComponent]( [param:Integer index], [param:Integer component], [param:Float value] ) </h3>
  182. <p>Sets the given component of the vector at the given index.</p>
  183. <h3>[method:this setX]( [param:Integer index], [param:Float x] )</h3>
  184. <p>Sets the x component of the vector at the given index.</p>
  185. <h3>[method:this setY]( [param:Integer index], [param:Float y] )</h3>
  186. <p>Sets the y component of the vector at the given index.</p>
  187. <h3>[method:this setZ]( [param:Integer index], [param:Float z] )</h3>
  188. <p>Sets the z component of the vector at the given index.</p>
  189. <h3>[method:this setW]( [param:Integer index], [param:Float w] )</h3>
  190. <p>Sets the w component of the vector at the given index.</p>
  191. <h3>[method:this setXY]( [param:Integer index], [param:Float x], [param:Float y] )</h3>
  192. <p>Sets the x and y components of the vector at the given index.</p>
  193. <h3>[method:this setXYZ]( [param:Integer index], [param:Float x], [param:Float y], [param:Float z] )</h3>
  194. <p>Sets the x, y and z components of the vector at the given index.</p>
  195. <h3>[method:this setXYZW]( [param:Integer index], [param:Float x], [param:Float y], [param:Float z], [param:Float w] )
  196. </h3>
  197. <p>Sets the x, y, z and w components of the vector at the given index.</p>
  198. <h2>Source</h2>
  199. <p>
  200. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  201. </p>
  202. </body>
  203. </html>