BufferAttributeNode.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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"><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>
  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">
  45. <strong>value</strong>
  46. </td>
  47. <td class="description last">
  48. <p>The attribute data.</p>
  49. </td>
  50. </tr>
  51. <tr>
  52. <td class="name">
  53. <strong>bufferType</strong>
  54. </td>
  55. <td class="description last">
  56. <p>The buffer type (e.g. <code>'vec3'</code>).</p>
  57. <p>Default is <code>null</code>.</p>
  58. </td>
  59. </tr>
  60. <tr>
  61. <td class="name">
  62. <strong>bufferStride</strong>
  63. </td>
  64. <td class="description last">
  65. <p>The buffer stride.</p>
  66. <p>Default is <code>0</code>.</p>
  67. </td>
  68. </tr>
  69. <tr>
  70. <td class="name">
  71. <strong>bufferOffset</strong>
  72. </td>
  73. <td class="description last">
  74. <p>The buffer offset.</p>
  75. <p>Default is <code>0</code>.</p>
  76. </td>
  77. </tr>
  78. </tbody>
  79. </table>
  80. </div>
  81. </div>
  82. <h2 class="subsection-title">Properties</h2>
  83. <div class="member">
  84. <h3 class="name" id="attribute" translate="no">.<a href="#attribute">attribute</a><span class="type-signature"> : <a href="BufferAttribute.html">BufferAttribute</a></span> </h3>
  85. <div class="description">
  86. <p>A reference to the buffer attribute.</p>
  87. <p>Default is <code>null</code>.</p>
  88. </div>
  89. </div>
  90. <div class="member">
  91. <h3 class="name" id="bufferOffset" translate="no">.<a href="#bufferOffset">bufferOffset</a><span class="type-signature"> : number</span> </h3>
  92. <div class="description">
  93. <p>The buffer offset.</p>
  94. <p>Default is <code>0</code>.</p>
  95. </div>
  96. </div>
  97. <div class="member">
  98. <h3 class="name" id="bufferStride" translate="no">.<a href="#bufferStride">bufferStride</a><span class="type-signature"> : number</span> </h3>
  99. <div class="description">
  100. <p>The buffer stride.</p>
  101. <p>Default is <code>0</code>.</p>
  102. </div>
  103. </div>
  104. <div class="member">
  105. <h3 class="name" id="bufferType" translate="no">.<a href="#bufferType">bufferType</a><span class="type-signature"> : string</span> </h3>
  106. <div class="description">
  107. <p>The buffer type (e.g. <code>'vec3'</code>).</p>
  108. <p>Default is <code>null</code>.</p>
  109. </div>
  110. </div>
  111. <div class="member">
  112. <h3 class="name" id="global" translate="no">.<a href="#global">global</a><span class="type-signature"> : boolean</span> </h3>
  113. <div class="description">
  114. <p><code>BufferAttributeNode</code> sets this property to <code>true</code> by default.</p>
  115. <p>Default is <code>true</code>.</p>
  116. </div>
  117. <dl class="details">
  118. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="InputNode.html#global">InputNode#global</a></dt>
  119. </dl>
  120. </div>
  121. <div class="member">
  122. <h3 class="name" id="instanced" translate="no">.<a href="#instanced">instanced</a><span class="type-signature"> : boolean</span> </h3>
  123. <div class="description">
  124. <p>Whether the attribute is instanced or not.</p>
  125. <p>Default is <code>false</code>.</p>
  126. </div>
  127. </div>
  128. <div class="member">
  129. <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>
  130. <div class="description">
  131. <p>This flag can be used for type testing.</p>
  132. <p>Default is <code>true</code>.</p>
  133. </div>
  134. </div>
  135. <div class="member">
  136. <h3 class="name" id="usage" translate="no">.<a href="#usage">usage</a><span class="type-signature"> : number</span> </h3>
  137. <div class="description">
  138. <p>The usage property. Set this to <code>THREE.DynamicDrawUsage</code> via <code>.setUsage()</code>,
  139. if you are planning to update the attribute data per frame.</p>
  140. <p>Default is <code>StaticDrawUsage</code>.</p>
  141. </div>
  142. </div>
  143. <h2 class="subsection-title">Methods</h2>
  144. <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>
  145. <div class="method">
  146. <div class="description">
  147. <p>Generates the code snippet of the buffer attribute node.</p>
  148. </div>
  149. <table class="params">
  150. <tbody>
  151. <tr>
  152. <td class="name">
  153. <strong>builder</strong>
  154. </td>
  155. <td class="description last">
  156. <p>The current node builder.</p>
  157. </td>
  158. </tr>
  159. </tbody>
  160. </table>
  161. <dl class="details">
  162. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="InputNode.html#generate">InputNode#generate</a></dt>
  163. </dl>
  164. <dl class="details">
  165. <dt class="tag-returns"><strong>Returns:</strong> The generated code snippet.</dt>
  166. </dl>
  167. </div>
  168. <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>
  169. <div class="method">
  170. <div class="description">
  171. <p>This method is overwritten since the attribute data might be shared
  172. and thus the hash should be shared as well.</p>
  173. </div>
  174. <table class="params">
  175. <tbody>
  176. <tr>
  177. <td class="name">
  178. <strong>builder</strong>
  179. </td>
  180. <td class="description last">
  181. <p>The current node builder.</p>
  182. </td>
  183. </tr>
  184. </tbody>
  185. </table>
  186. <dl class="details">
  187. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="InputNode.html#getHash">InputNode#getHash</a></dt>
  188. </dl>
  189. <dl class="details">
  190. <dt class="tag-returns"><strong>Returns:</strong> The hash.</dt>
  191. </dl>
  192. </div>
  193. <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>
  194. <div class="method">
  195. <div class="description">
  196. <p>Overwrites the default implementation to return a fixed value <code>'bufferAttribute'</code>.</p>
  197. </div>
  198. <table class="params">
  199. <tbody>
  200. <tr>
  201. <td class="name">
  202. <strong>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#getInputType">InputNode#getInputType</a></dt>
  212. </dl>
  213. <dl class="details">
  214. <dt class="tag-returns"><strong>Returns:</strong> The input type.</dt>
  215. </dl>
  216. </div>
  217. <h3 class="name name-method" id="getNodeType" translate="no">.<a href="#getNodeType">getNodeType</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>This method is overwritten since the node type is inferred from
  221. the buffer attribute.</p>
  222. </div>
  223. <table class="params">
  224. <tbody>
  225. <tr>
  226. <td class="name">
  227. <strong>builder</strong>
  228. </td>
  229. <td class="description last">
  230. <p>The current node builder.</p>
  231. </td>
  232. </tr>
  233. </tbody>
  234. </table>
  235. <dl class="details">
  236. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="InputNode.html#getNodeType">InputNode#getNodeType</a></dt>
  237. </dl>
  238. <dl class="details">
  239. <dt class="tag-returns"><strong>Returns:</strong> The node type.</dt>
  240. </dl>
  241. </div>
  242. <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>
  243. <div class="method">
  244. <div class="description">
  245. <p>Sets the <code>instanced</code> property to the given value.</p>
  246. </div>
  247. <table class="params">
  248. <tbody>
  249. <tr>
  250. <td class="name">
  251. <strong>value</strong>
  252. </td>
  253. <td class="description last">
  254. <p>The value to set.</p>
  255. </td>
  256. </tr>
  257. </tbody>
  258. </table>
  259. <dl class="details">
  260. <dt class="tag-returns"><strong>Returns:</strong> A reference to this node.</dt>
  261. </dl>
  262. </div>
  263. <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>
  264. <div class="method">
  265. <div class="description">
  266. <p>Sets the <code>usage</code> property to the given value.</p>
  267. </div>
  268. <table class="params">
  269. <tbody>
  270. <tr>
  271. <td class="name">
  272. <strong>value</strong>
  273. </td>
  274. <td class="description last">
  275. <p>The usage to set.</p>
  276. </td>
  277. </tr>
  278. </tbody>
  279. </table>
  280. <dl class="details">
  281. <dt class="tag-returns"><strong>Returns:</strong> A reference to this node.</dt>
  282. </dl>
  283. </div>
  284. <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>
  285. <div class="method">
  286. <div class="description">
  287. <p>Depending on which value was passed to the node, <code>setup()</code> behaves
  288. differently. If no instance of <code>BufferAttribute</code> was passed, the method
  289. creates an internal attribute and configures it respectively.</p>
  290. </div>
  291. <table class="params">
  292. <tbody>
  293. <tr>
  294. <td class="name">
  295. <strong>builder</strong>
  296. </td>
  297. <td class="description last">
  298. <p>The current node builder.</p>
  299. </td>
  300. </tr>
  301. </tbody>
  302. </table>
  303. <dl class="details">
  304. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="InputNode.html#setup">InputNode#setup</a></dt>
  305. </dl>
  306. </div>
  307. <h2 class="subsection-title">Source</h2>
  308. <p>
  309. <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>
  310. </p>
  311. </article>
  312. </section>
  313. <script src="../scripts/linenumber.js"></script>
  314. <script src="../scripts/page.js"></script>
  315. </body>
  316. </html>
粤ICP备19079148号