BufferAttributeNode.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>BufferAttributeNode - Three.js Docs</title>
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <script src="../scripts/highlight.min.js"></script>
  8. <link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
  9. <link type="text/css" rel="stylesheet" href="../styles/page.css">
  10. </head>
  11. <body>
  12. <p class="inheritance" translate="no"><a href="EventDispatcher.html">EventDispatcher</a> → <a href="Node.html">Node</a> → <a href="InputNode.html">InputNode</a> → </p>
  13. <h1 translate="no">BufferAttributeNode</h1>
  14. <section>
  15. <header>
  16. <div class="class-description"><p>In earlier <code>three.js</code> versions it was only possible to define attribute data
  17. on geometry level. With <code>BufferAttributeNode</code>, it is also possible to do this
  18. on the node level.</p>
  19. <pre><code class="language-js">const geometry = new THREE.PlaneGeometry();
  20. const positionAttribute = geometry.getAttribute( 'position' );
  21. const colors = [];
  22. for ( let i = 0; i &lt; position.count; i ++ ) {
  23. colors.push( 1, 0, 0 );
  24. }
  25. material.colorNode = bufferAttribute( new THREE.Float32BufferAttribute( colors, 3 ) );
  26. </code></pre>
  27. <p>This new approach is especially interesting when geometry data are generated via
  28. compute shaders. The below line converts a storage buffer into an attribute node.</p>
  29. <pre><code class="language-js">material.positionNode = positionBuffer.toAttribute();
  30. </code></pre></div>
  31. </header>
  32. <article>
  33. <div class="container-overview">
  34. <h2>Constructor</h2>
  35. <h3 class="name name-method" id="BufferAttributeNode" translate="no">new <a href="#BufferAttributeNode">BufferAttributeNode</a><span class="signature">( value : <span class="param-type"><a href="BufferAttribute.html">BufferAttribute</a> | <a href="InterleavedBuffer.html">InterleavedBuffer</a> | TypedArray</span>, bufferType : <span class="param-type">string</span>, bufferStride : <span class="param-type">number</span>, bufferOffset : <span class="param-type">number</span> )</span> </h3>
  36. <div class="method">
  37. <div class="description">
  38. <p>Constructs a new buffer attribute node.</p>
  39. </div>
  40. <table class="params">
  41. <tbody>
  42. <tr>
  43. <td class="name">
  44. <strong translate="no">value</strong>
  45. </td>
  46. <td class="description last">
  47. <p>The attribute data.</p>
  48. </td>
  49. </tr>
  50. <tr>
  51. <td class="name">
  52. <strong translate="no">bufferType</strong>
  53. </td>
  54. <td class="description last">
  55. <p>The buffer type (e.g. <code>'vec3'</code>).</p>
  56. <p>Default is <code>null</code>.</p>
  57. </td>
  58. </tr>
  59. <tr>
  60. <td class="name">
  61. <strong translate="no">bufferStride</strong>
  62. </td>
  63. <td class="description last">
  64. <p>The buffer stride.</p>
  65. <p>Default is <code>0</code>.</p>
  66. </td>
  67. </tr>
  68. <tr>
  69. <td class="name">
  70. <strong translate="no">bufferOffset</strong>
  71. </td>
  72. <td class="description last">
  73. <p>The buffer offset.</p>
  74. <p>Default is <code>0</code>.</p>
  75. </td>
  76. </tr>
  77. </tbody>
  78. </table>
  79. </div>
  80. </div>
  81. <h2 class="subsection-title">Properties</h2>
  82. <div class="member">
  83. <h3 class="name" id="attribute" translate="no">.<a href="#attribute">attribute</a><span class="type-signature"> : <a href="BufferAttribute.html">BufferAttribute</a></span> </h3>
  84. <div class="description">
  85. <p>A reference to the buffer attribute.</p>
  86. <p>Default is <code>null</code>.</p>
  87. </div>
  88. </div>
  89. <div class="member">
  90. <h3 class="name" id="bufferOffset" translate="no">.<a href="#bufferOffset">bufferOffset</a><span class="type-signature"> : number</span> </h3>
  91. <div class="description">
  92. <p>The buffer offset.</p>
  93. <p>Default is <code>0</code>.</p>
  94. </div>
  95. </div>
  96. <div class="member">
  97. <h3 class="name" id="bufferStride" translate="no">.<a href="#bufferStride">bufferStride</a><span class="type-signature"> : number</span> </h3>
  98. <div class="description">
  99. <p>The buffer stride.</p>
  100. <p>Default is <code>0</code>.</p>
  101. </div>
  102. </div>
  103. <div class="member">
  104. <h3 class="name" id="bufferType" translate="no">.<a href="#bufferType">bufferType</a><span class="type-signature"> : string</span> </h3>
  105. <div class="description">
  106. <p>The buffer type (e.g. <code>'vec3'</code>).</p>
  107. <p>Default is <code>null</code>.</p>
  108. </div>
  109. </div>
  110. <div class="member">
  111. <h3 class="name" id="global" translate="no">.<a href="#global">global</a><span class="type-signature"> : boolean</span> </h3>
  112. <div class="description">
  113. <p><code>BufferAttributeNode</code> sets this property to <code>true</code> by default.</p>
  114. <p>Default is <code>true</code>.</p>
  115. </div>
  116. <dl class="details">
  117. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="InputNode.html#global">InputNode#global</a></dt>
  118. </dl>
  119. </div>
  120. <div class="member">
  121. <h3 class="name" id="instanced" translate="no">.<a href="#instanced">instanced</a><span class="type-signature"> : boolean</span> </h3>
  122. <div class="description">
  123. <p>Whether the attribute is instanced or not.</p>
  124. <p>Default is <code>false</code>.</p>
  125. </div>
  126. </div>
  127. <div class="member">
  128. <h3 class="name" id="isBufferNode" translate="no">.<a href="#isBufferNode">isBufferNode</a><span class="type-signature"> : boolean</span> <span class="type-signature">(readonly) </span></h3>
  129. <div class="description">
  130. <p>This flag can be used for type testing.</p>
  131. <p>Default is <code>true</code>.</p>
  132. </div>
  133. </div>
  134. <div class="member">
  135. <h3 class="name" id="usage" translate="no">.<a href="#usage">usage</a><span class="type-signature"> : number</span> </h3>
  136. <div class="description">
  137. <p>The usage property. Set this to <code>THREE.DynamicDrawUsage</code> via <code>.setUsage()</code>,
  138. if you are planning to update the attribute data per frame.</p>
  139. <p>Default is <code>StaticDrawUsage</code>.</p>
  140. </div>
  141. </div>
  142. <h2 class="subsection-title">Methods</h2>
  143. <h3 class="name name-method" id="generate" translate="no">.<a href="#generate">generate</a><span class="signature">( builder : <span class="param-type"><a href="NodeBuilder.html">NodeBuilder</a></span> )</span><span class="type-signature"> : string</span> </h3>
  144. <div class="method">
  145. <div class="description">
  146. <p>Generates the code snippet of the buffer attribute node.</p>
  147. </div>
  148. <table class="params">
  149. <tbody>
  150. <tr>
  151. <td class="name">
  152. <strong translate="no">builder</strong>
  153. </td>
  154. <td class="description last">
  155. <p>The current node builder.</p>
  156. </td>
  157. </tr>
  158. </tbody>
  159. </table>
  160. <dl class="details">
  161. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="InputNode.html#generate">InputNode#generate</a></dt>
  162. </dl>
  163. <dl class="details">
  164. <dt class="tag-returns"><strong>Returns:</strong> The generated code snippet.</dt>
  165. </dl>
  166. </div>
  167. <h3 class="name name-method" id="generateNodeType" translate="no">.<a href="#generateNodeType">generateNodeType</a><span class="signature">( builder : <span class="param-type"><a href="NodeBuilder.html">NodeBuilder</a></span> )</span><span class="type-signature"> : string</span> </h3>
  168. <div class="method">
  169. <div class="description">
  170. <p>This method is overwritten since the node type is inferred from
  171. the buffer attribute.</p>
  172. </div>
  173. <table class="params">
  174. <tbody>
  175. <tr>
  176. <td class="name">
  177. <strong translate="no">builder</strong>
  178. </td>
  179. <td class="description last">
  180. <p>The current node builder.</p>
  181. </td>
  182. </tr>
  183. </tbody>
  184. </table>
  185. <dl class="details">
  186. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="InputNode.html#generateNodeType">InputNode#generateNodeType</a></dt>
  187. </dl>
  188. <dl class="details">
  189. <dt class="tag-returns"><strong>Returns:</strong> The node type.</dt>
  190. </dl>
  191. </div>
  192. <h3 class="name name-method" id="getHash" translate="no">.<a href="#getHash">getHash</a><span class="signature">( builder : <span class="param-type"><a href="NodeBuilder.html">NodeBuilder</a></span> )</span><span class="type-signature"> : string</span> </h3>
  193. <div class="method">
  194. <div class="description">
  195. <p>This method is overwritten since the attribute data might be shared
  196. and thus the hash should be shared as well.</p>
  197. </div>
  198. <table class="params">
  199. <tbody>
  200. <tr>
  201. <td class="name">
  202. <strong translate="no">builder</strong>
  203. </td>
  204. <td class="description last">
  205. <p>The current node builder.</p>
  206. </td>
  207. </tr>
  208. </tbody>
  209. </table>
  210. <dl class="details">
  211. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="InputNode.html#getHash">InputNode#getHash</a></dt>
  212. </dl>
  213. <dl class="details">
  214. <dt class="tag-returns"><strong>Returns:</strong> The hash.</dt>
  215. </dl>
  216. </div>
  217. <h3 class="name name-method" id="getInputType" translate="no">.<a href="#getInputType">getInputType</a><span class="signature">( builder : <span class="param-type"><a href="NodeBuilder.html">NodeBuilder</a></span> )</span><span class="type-signature"> : string</span> </h3>
  218. <div class="method">
  219. <div class="description">
  220. <p>Overwrites the default implementation to return a fixed value <code>'bufferAttribute'</code>.</p>
  221. </div>
  222. <table class="params">
  223. <tbody>
  224. <tr>
  225. <td class="name">
  226. <strong translate="no">builder</strong>
  227. </td>
  228. <td class="description last">
  229. <p>The current node builder.</p>
  230. </td>
  231. </tr>
  232. </tbody>
  233. </table>
  234. <dl class="details">
  235. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="InputNode.html#getInputType">InputNode#getInputType</a></dt>
  236. </dl>
  237. <dl class="details">
  238. <dt class="tag-returns"><strong>Returns:</strong> The input type.</dt>
  239. </dl>
  240. </div>
  241. <h3 class="name name-method" id="setInstanced" translate="no">.<a href="#setInstanced">setInstanced</a><span class="signature">( value : <span class="param-type">boolean</span> )</span><span class="type-signature"> : <a href="BufferAttributeNode.html">BufferAttributeNode</a></span> </h3>
  242. <div class="method">
  243. <div class="description">
  244. <p>Sets the <code>instanced</code> property to the given value.</p>
  245. </div>
  246. <table class="params">
  247. <tbody>
  248. <tr>
  249. <td class="name">
  250. <strong translate="no">value</strong>
  251. </td>
  252. <td class="description last">
  253. <p>The value to set.</p>
  254. </td>
  255. </tr>
  256. </tbody>
  257. </table>
  258. <dl class="details">
  259. <dt class="tag-returns"><strong>Returns:</strong> A reference to this node.</dt>
  260. </dl>
  261. </div>
  262. <h3 class="name name-method" id="setUsage" translate="no">.<a href="#setUsage">setUsage</a><span class="signature">( value : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="BufferAttributeNode.html">BufferAttributeNode</a></span> </h3>
  263. <div class="method">
  264. <div class="description">
  265. <p>Sets the <code>usage</code> property to the given value.</p>
  266. </div>
  267. <table class="params">
  268. <tbody>
  269. <tr>
  270. <td class="name">
  271. <strong translate="no">value</strong>
  272. </td>
  273. <td class="description last">
  274. <p>The usage to set.</p>
  275. </td>
  276. </tr>
  277. </tbody>
  278. </table>
  279. <dl class="details">
  280. <dt class="tag-returns"><strong>Returns:</strong> A reference to this node.</dt>
  281. </dl>
  282. </div>
  283. <h3 class="name name-method" id="setup" translate="no">.<a href="#setup">setup</a><span class="signature">( builder : <span class="param-type"><a href="NodeBuilder.html">NodeBuilder</a></span> )</span> </h3>
  284. <div class="method">
  285. <div class="description">
  286. <p>Depending on which value was passed to the node, <code>setup()</code> behaves
  287. differently. If no instance of <code>BufferAttribute</code> was passed, the method
  288. creates an internal attribute and configures it respectively.</p>
  289. </div>
  290. <table class="params">
  291. <tbody>
  292. <tr>
  293. <td class="name">
  294. <strong translate="no">builder</strong>
  295. </td>
  296. <td class="description last">
  297. <p>The current node builder.</p>
  298. </td>
  299. </tr>
  300. </tbody>
  301. </table>
  302. <dl class="details">
  303. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="InputNode.html#setup">InputNode#setup</a></dt>
  304. </dl>
  305. </div>
  306. <h2 class="subsection-title">Source</h2>
  307. <p>
  308. <a href="https://github.com/mrdoob/three.js/blob/master/src/nodes/accessors/BufferAttributeNode.js" translate="no" target="_blank" rel="noopener">src/nodes/accessors/BufferAttributeNode.js</a>
  309. </p>
  310. </article>
  311. </section>
  312. <script src="../scripts/linenumber.js"></script>
  313. <script src="../scripts/page.js"></script>
  314. </body>
  315. </html>
粤ICP备19079148号