BufferAttributeNode.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. <p>This new approach is especially interesting when geometry data are generated via
  20. compute shaders. The below line converts a storage buffer into an attribute node.</p>
  21. <pre><code class="language-js">material.positionNode = positionBuffer.toAttribute();
  22. </code></pre></div>
  23. <h2>Code Example</h2>
  24. <div translate="no"><pre><code class="language-js">const geometry = new THREE.PlaneGeometry();
  25. const positionAttribute = geometry.getAttribute( 'position' );
  26. const colors = [];
  27. for ( let i = 0; i &lt; position.count; i ++ ) {
  28. colors.push( 1, 0, 0 );
  29. }
  30. material.colorNode = bufferAttribute( new THREE.Float32BufferAttribute( colors, 3 ) );
  31. </code></pre></div>
  32. </header>
  33. <article>
  34. <div class="container-overview">
  35. <h2>Constructor</h2>
  36. <h3 class="name name-method" id="BufferAttributeNode" translate="no">new <a href="#BufferAttributeNode">BufferAttributeNode</a><span class="signature">( value : <span class="param-type">BufferAttribute | InterleavedBuffer | 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>
  37. <div class="method">
  38. <div class="description">
  39. <p>Constructs a new buffer attribute node.</p>
  40. </div>
  41. <table class="params">
  42. <tbody>
  43. <tr>
  44. <td class="name"><code>value</code></td>
  45. <td class="description last"><p>The attribute data.</p></td>
  46. </tr>
  47. <tr>
  48. <td class="name"><code>bufferType</code></td>
  49. <td class="description last"><p>The buffer type (e.g. <code>'vec3'</code>).<br/>Default is <code>null</code>.</p></td>
  50. </tr>
  51. <tr>
  52. <td class="name"><code>bufferStride</code></td>
  53. <td class="description last"><p>The buffer stride.<br/>Default is <code>0</code>.</p></td>
  54. </tr>
  55. <tr>
  56. <td class="name"><code>bufferOffset</code></td>
  57. <td class="description last"><p>The buffer offset.<br/>Default is <code>0</code>.</p></td>
  58. </tr>
  59. </tbody>
  60. </table>
  61. </div>
  62. </div>
  63. <h2 class="subsection-title">Properties</h2>
  64. <div class="member">
  65. <h3 class="name" id="attribute" translate="no">.<a href="#attribute">attribute</a><span class="type-signature"> : <a href="BufferAttribute.html">BufferAttribute</a></span> </h3>
  66. <div class="description">
  67. <p>A reference to the buffer attribute.<br/>Default is <code>null</code>.</p>
  68. </div>
  69. </div>
  70. <div class="member">
  71. <h3 class="name" id="bufferOffset" translate="no">.<a href="#bufferOffset">bufferOffset</a><span class="type-signature"> : number</span> </h3>
  72. <div class="description">
  73. <p>The buffer offset.<br/>Default is <code>0</code>.</p>
  74. </div>
  75. </div>
  76. <div class="member">
  77. <h3 class="name" id="bufferStride" translate="no">.<a href="#bufferStride">bufferStride</a><span class="type-signature"> : number</span> </h3>
  78. <div class="description">
  79. <p>The buffer stride.<br/>Default is <code>0</code>.</p>
  80. </div>
  81. </div>
  82. <div class="member">
  83. <h3 class="name" id="bufferType" translate="no">.<a href="#bufferType">bufferType</a><span class="type-signature"> : string</span> </h3>
  84. <div class="description">
  85. <p>The buffer type (e.g. <code>'vec3'</code>).<br/>Default is <code>null</code>.</p>
  86. </div>
  87. </div>
  88. <div class="member">
  89. <h3 class="name" id="global" translate="no">.<a href="#global">global</a><span class="type-signature"> : boolean</span> </h3>
  90. <div class="description">
  91. <p><code>BufferAttributeNode</code> sets this property to <code>true</code> by default.<br/>Default is <code>true</code>.</p>
  92. </div>
  93. <dl class="details">
  94. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="InputNode.html#global">InputNode#global</a></dt>
  95. </dl>
  96. </div>
  97. <div class="member">
  98. <h3 class="name" id="instanced" translate="no">.<a href="#instanced">instanced</a><span class="type-signature"> : boolean</span> </h3>
  99. <div class="description">
  100. <p>Whether the attribute is instanced or not.<br/>Default is <code>false</code>.</p>
  101. </div>
  102. </div>
  103. <div class="member">
  104. <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>
  105. <div class="description">
  106. <p>This flag can be used for type testing.<br/>Default is <code>true</code>.</p>
  107. </div>
  108. </div>
  109. <div class="member">
  110. <h3 class="name" id="usage" translate="no">.<a href="#usage">usage</a><span class="type-signature"> : number</span> </h3>
  111. <div class="description">
  112. <p>The usage property. Set this to <code>THREE.DynamicDrawUsage</code> via <code>.setUsage()</code>,
  113. if you are planning to update the attribute data per frame.<br/>Default is <code>StaticDrawUsage</code>.</p>
  114. </div>
  115. </div>
  116. <h2 class="subsection-title">Methods</h2>
  117. <h3 class="name name-method" id="generate" translate="no">.<a href="#generate">generate</a><span class="signature">( builder : <span class="param-type">NodeBuilder</span> )</span><span class="type-signature"> : string</span> </h3>
  118. <div class="method">
  119. <div class="description">
  120. <p>Generates the code snippet of the buffer attribute node.</p>
  121. </div>
  122. <table class="params">
  123. <tbody>
  124. <tr>
  125. <td class="name"><code>builder</code></td>
  126. <td class="description last"><p>The current node builder.</p></td>
  127. </tr>
  128. </tbody>
  129. </table>
  130. <dl class="details">
  131. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="InputNode.html#generate">InputNode#generate</a></dt>
  132. </dl>
  133. <dl class="details">
  134. <dt class="tag-returns"><strong>Returns:</strong> The generated code snippet.</dt>
  135. </dl>
  136. </div>
  137. <h3 class="name name-method" id="getHash" translate="no">.<a href="#getHash">getHash</a><span class="signature">( builder : <span class="param-type">NodeBuilder</span> )</span><span class="type-signature"> : string</span> </h3>
  138. <div class="method">
  139. <div class="description">
  140. <p>This method is overwritten since the attribute data might be shared
  141. and thus the hash should be shared as well.</p>
  142. </div>
  143. <table class="params">
  144. <tbody>
  145. <tr>
  146. <td class="name"><code>builder</code></td>
  147. <td class="description last"><p>The current node builder.</p></td>
  148. </tr>
  149. </tbody>
  150. </table>
  151. <dl class="details">
  152. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="InputNode.html#getHash">InputNode#getHash</a></dt>
  153. </dl>
  154. <dl class="details">
  155. <dt class="tag-returns"><strong>Returns:</strong> The hash.</dt>
  156. </dl>
  157. </div>
  158. <h3 class="name name-method" id="getInputType" translate="no">.<a href="#getInputType">getInputType</a><span class="signature">( builder : <span class="param-type">NodeBuilder</span> )</span><span class="type-signature"> : string</span> </h3>
  159. <div class="method">
  160. <div class="description">
  161. <p>Overwrites the default implementation to return a fixed value <code>'bufferAttribute'</code>.</p>
  162. </div>
  163. <table class="params">
  164. <tbody>
  165. <tr>
  166. <td class="name"><code>builder</code></td>
  167. <td class="description last"><p>The current node builder.</p></td>
  168. </tr>
  169. </tbody>
  170. </table>
  171. <dl class="details">
  172. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="InputNode.html#getInputType">InputNode#getInputType</a></dt>
  173. </dl>
  174. <dl class="details">
  175. <dt class="tag-returns"><strong>Returns:</strong> The input type.</dt>
  176. </dl>
  177. </div>
  178. <h3 class="name name-method" id="getNodeType" translate="no">.<a href="#getNodeType">getNodeType</a><span class="signature">( builder : <span class="param-type">NodeBuilder</span> )</span><span class="type-signature"> : string</span> </h3>
  179. <div class="method">
  180. <div class="description">
  181. <p>This method is overwritten since the node type is inferred from
  182. the buffer attribute.</p>
  183. </div>
  184. <table class="params">
  185. <tbody>
  186. <tr>
  187. <td class="name"><code>builder</code></td>
  188. <td class="description last"><p>The current node builder.</p></td>
  189. </tr>
  190. </tbody>
  191. </table>
  192. <dl class="details">
  193. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="InputNode.html#getNodeType">InputNode#getNodeType</a></dt>
  194. </dl>
  195. <dl class="details">
  196. <dt class="tag-returns"><strong>Returns:</strong> The node type.</dt>
  197. </dl>
  198. </div>
  199. <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>
  200. <div class="method">
  201. <div class="description">
  202. <p>Sets the <code>instanced</code> property to the given value.</p>
  203. </div>
  204. <table class="params">
  205. <tbody>
  206. <tr>
  207. <td class="name"><code>value</code></td>
  208. <td class="description last"><p>The value to set.</p></td>
  209. </tr>
  210. </tbody>
  211. </table>
  212. <dl class="details">
  213. <dt class="tag-returns"><strong>Returns:</strong> A reference to this node.</dt>
  214. </dl>
  215. </div>
  216. <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>
  217. <div class="method">
  218. <div class="description">
  219. <p>Sets the <code>usage</code> property to the given value.</p>
  220. </div>
  221. <table class="params">
  222. <tbody>
  223. <tr>
  224. <td class="name"><code>value</code></td>
  225. <td class="description last"><p>The usage to set.</p></td>
  226. </tr>
  227. </tbody>
  228. </table>
  229. <dl class="details">
  230. <dt class="tag-returns"><strong>Returns:</strong> A reference to this node.</dt>
  231. </dl>
  232. </div>
  233. <h3 class="name name-method" id="setup" translate="no">.<a href="#setup">setup</a><span class="signature">( builder : <span class="param-type">NodeBuilder</span> )</span> </h3>
  234. <div class="method">
  235. <div class="description">
  236. <p>Depending on which value was passed to the node, <code>setup()</code> behaves
  237. differently. If no instance of <code>BufferAttribute</code> was passed, the method
  238. creates an internal attribute and configures it respectively.</p>
  239. </div>
  240. <table class="params">
  241. <tbody>
  242. <tr>
  243. <td class="name"><code>builder</code></td>
  244. <td class="description last"><p>The current node builder.</p></td>
  245. </tr>
  246. </tbody>
  247. </table>
  248. <dl class="details">
  249. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="InputNode.html#setup">InputNode#setup</a></dt>
  250. </dl>
  251. </div>
  252. <h2 class="subsection-title">Source</h2>
  253. <p>
  254. <a href="https://github.com/mrdoob/three.js/blob/master/src/nodes/accessors/BufferAttributeNode.js" target="_blank" rel="noopener" translate="no">src/nodes/accessors/BufferAttributeNode.js</a>
  255. </p>
  256. </article>
  257. </section>
  258. <script src="../scripts/linenumber.js"></script>
  259. <script src="../scripts/page.js"></script>
  260. </body>
  261. </html>
粤ICP备19079148号