LoopNode.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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;<a href="global.html#any">any</a>></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">
  52. <strong>params</strong>
  53. </td>
  54. <td class="description last">
  55. <p>Depending on the loop type, array holds different parameterization values for the loop.</p>
  56. </td>
  57. </tr>
  58. </tbody>
  59. </table>
  60. </div>
  61. </div>
  62. <h2 class="subsection-title">Methods</h2>
  63. <h3 class="name name-method" id="getProperties" translate="no">.<a href="#getProperties">getProperties</a><span class="signature">( builder : <span class="param-type"><a href="NodeBuilder.html">NodeBuilder</a></span> )</span><span class="type-signature"> : Object</span> </h3>
  64. <div class="method">
  65. <div class="description">
  66. <p>Returns properties about this node.</p>
  67. </div>
  68. <table class="params">
  69. <tbody>
  70. <tr>
  71. <td class="name">
  72. <strong>builder</strong>
  73. </td>
  74. <td class="description last">
  75. <p>The current node builder.</p>
  76. </td>
  77. </tr>
  78. </tbody>
  79. </table>
  80. <dl class="details">
  81. <dt class="tag-returns"><strong>Returns:</strong> The node properties.</dt>
  82. </dl>
  83. </div>
  84. <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>
  85. <div class="method">
  86. <div class="description">
  87. <p>Returns a loop variable name based on an index. The pattern is
  88. <code>0</code> = <code>i</code>, <code>1</code>= <code>j</code>, <code>2</code>= <code>k</code> and so on.</p>
  89. </div>
  90. <table class="params">
  91. <tbody>
  92. <tr>
  93. <td class="name">
  94. <strong>index</strong>
  95. </td>
  96. <td class="description last">
  97. <p>The index.</p>
  98. </td>
  99. </tr>
  100. </tbody>
  101. </table>
  102. <dl class="details">
  103. <dt class="tag-returns"><strong>Returns:</strong> The loop variable name.</dt>
  104. </dl>
  105. </div>
  106. <h2 class="subsection-title">Source</h2>
  107. <p>
  108. <a href="https://github.com/mrdoob/three.js/blob/master/src/nodes/utils/LoopNode.js" translate="no" target="_blank" rel="noopener">src/nodes/utils/LoopNode.js</a>
  109. </p>
  110. </article>
  111. </section>
  112. <script src="../scripts/linenumber.js"></script>
  113. <script src="../scripts/page.js"></script>
  114. </body>
  115. </html>
粤ICP备19079148号