LoopNode.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>LoopNode - 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> → </p>
  13. <h1 translate="no">LoopNode</h1>
  14. <section>
  15. <header>
  16. <div class="class-description"><p>This module offers a variety of ways to implement loops in TSL. In it's basic form it's:</p>
  17. <p>However, it is also possible to define a start and end ranges, data types and loop conditions:</p>
  18. <pre><code class="language-js">Loop( { start: int( 0 ), end: int( 10 ), type: 'int', condition: '&lt;' }, ( { i } ) => {
  19. } );
  20. </code></pre>
  21. <p>Nested loops can be defined in a compacted form:</p>
  22. <pre><code class="language-js">Loop( 10, 5, ( { i, j } ) => {
  23. } );
  24. </code></pre>
  25. <p>Loops that should run backwards can be defined like so:</p>
  26. <pre><code class="language-js">Loop( { start: 10 }, () => {} );
  27. </code></pre>
  28. <p>It is possible to execute with boolean values, similar to the <code>while</code> syntax.</p>
  29. <pre><code class="language-js">const value = float( 0 ).toVar();
  30. Loop( value.lessThan( 10 ), () => {
  31. value.addAssign( 1 );
  32. } );
  33. </code></pre>
  34. <p>The module also provides <code>Break()</code> and <code>Continue()</code> TSL expression for loop control.</p></div>
  35. <h2>Code Example</h2>
  36. <div translate="no"><pre><code class="language-js">Loop( count, ( { i } ) => {
  37. } );
  38. </code></pre></div>
  39. </header>
  40. <article>
  41. <div class="container-overview">
  42. <h2>Constructor</h2>
  43. <h3 class="name name-method" id="LoopNode" translate="no">new <a href="#LoopNode">LoopNode</a><span class="signature">( params : <span class="param-type">Array.&lt;any></span> )</span> </h3>
  44. <div class="method">
  45. <div class="description">
  46. <p>Constructs a new loop node.</p>
  47. </div>
  48. <table class="params">
  49. <tbody>
  50. <tr>
  51. <td class="name"><code>params</code></td>
  52. <td class="description last"><p>Depending on the loop type, array holds different parameterization values for the loop.</p></td>
  53. </tr>
  54. </tbody>
  55. </table>
  56. </div>
  57. </div>
  58. <h2 class="subsection-title">Methods</h2>
  59. <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>
  60. <div class="method">
  61. <div class="description">
  62. <p>This method is overwritten since the node type is inferred based on the loop configuration.</p>
  63. </div>
  64. <table class="params">
  65. <tbody>
  66. <tr>
  67. <td class="name"><code>builder</code></td>
  68. <td class="description last"><p>The current node builder.</p></td>
  69. </tr>
  70. </tbody>
  71. </table>
  72. <dl class="details">
  73. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="Node.html#getNodeType">Node#getNodeType</a></dt>
  74. </dl>
  75. <dl class="details">
  76. <dt class="tag-returns"><strong>Returns:</strong> The node type.</dt>
  77. </dl>
  78. </div>
  79. <h3 class="name name-method" id="getProperties" translate="no">.<a href="#getProperties">getProperties</a><span class="signature">( builder : <span class="param-type">NodeBuilder</span> )</span><span class="type-signature"> : Object</span> </h3>
  80. <div class="method">
  81. <div class="description">
  82. <p>Returns properties about this node.</p>
  83. </div>
  84. <table class="params">
  85. <tbody>
  86. <tr>
  87. <td class="name"><code>builder</code></td>
  88. <td class="description last"><p>The current node builder.</p></td>
  89. </tr>
  90. </tbody>
  91. </table>
  92. <dl class="details">
  93. <dt class="tag-returns"><strong>Returns:</strong> The node properties.</dt>
  94. </dl>
  95. </div>
  96. <h3 class="name name-method" id="getVarName" translate="no">.<a href="#getVarName">getVarName</a><span class="signature">( index : <span class="param-type">number</span> )</span><span class="type-signature"> : string</span> </h3>
  97. <div class="method">
  98. <div class="description">
  99. <p>Returns a loop variable name based on an index. The pattern is
  100. <code>0</code> = <code>i</code>, <code>1</code>= <code>j</code>, <code>2</code>= <code>k</code> and so on.</p>
  101. </div>
  102. <table class="params">
  103. <tbody>
  104. <tr>
  105. <td class="name"><code>index</code></td>
  106. <td class="description last"><p>The index.</p></td>
  107. </tr>
  108. </tbody>
  109. </table>
  110. <dl class="details">
  111. <dt class="tag-returns"><strong>Returns:</strong> The loop variable name.</dt>
  112. </dl>
  113. </div>
  114. <h2 class="subsection-title">Source</h2>
  115. <p>
  116. <a href="https://github.com/mrdoob/three.js/blob/master/src/nodes/utils/LoopNode.js" target="_blank" rel="noopener" translate="no">src/nodes/utils/LoopNode.js</a>
  117. </p>
  118. </article>
  119. </section>
  120. <script src="../scripts/linenumber.js"></script>
  121. <script src="../scripts/page.js"></script>
  122. </body>
  123. </html>
粤ICP备19079148号