module-SceneUtils.html 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>SceneUtils - 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. <h1 translate="no">SceneUtils</h1>
  13. <section>
  14. <header>
  15. </header>
  16. <article>
  17. <h2 class="subsection-title">Import</h2>
  18. <p><span translate="no">SceneUtils</span> is an addon, and must be imported explicitly, see <a href="https://threejs.org/manual/#en/installation" target="_blank">Installation#Addons</a>.</p>
  19. <pre><code class="language-js">import * as SceneUtils from 'three/addons/utils/SceneUtils.js';</code></pre>
  20. <div class="container-overview">
  21. </div>
  22. <h2 class="subsection-title">Methods</h2>
  23. <h3 class="name name-method" id="~createMeshesFromInstancedMesh" translate="no">.<a href="#~createMeshesFromInstancedMesh">createMeshesFromInstancedMesh</a><span class="signature">( instancedMesh : <span class="param-type">InstancedMesh</span> )</span><span class="type-signature"> : <a href="Group.html">Group</a></span> <span class="type-signature">(inner) </span></h3>
  24. <div class="method">
  25. <div class="description">
  26. <p>This function creates a mesh for each instance of the given instanced mesh and
  27. adds it to a group. Each mesh will honor the current 3D transformation of its
  28. corresponding instance.</p>
  29. </div>
  30. <table class="params">
  31. <tbody>
  32. <tr>
  33. <td class="name"><code>instancedMesh</code></td>
  34. <td class="description last"><p>The instanced mesh.</p></td>
  35. </tr>
  36. </tbody>
  37. </table>
  38. <dl class="details">
  39. <dt class="tag-returns"><strong>Returns:</strong> A group of meshes.</dt>
  40. </dl>
  41. </div>
  42. <h3 class="name name-method" id="~createMeshesFromMultiMaterialMesh" translate="no">.<a href="#~createMeshesFromMultiMaterialMesh">createMeshesFromMultiMaterialMesh</a><span class="signature">( mesh : <span class="param-type">Mesh</span> )</span><span class="type-signature"> : <a href="Group.html">Group</a></span> <span class="type-signature">(inner) </span></h3>
  43. <div class="method">
  44. <div class="description">
  45. <p>This function creates a mesh for each geometry-group of the given multi-material mesh and
  46. adds it to a group.</p>
  47. </div>
  48. <table class="params">
  49. <tbody>
  50. <tr>
  51. <td class="name"><code>mesh</code></td>
  52. <td class="description last"><p>The multi-material mesh.</p></td>
  53. </tr>
  54. </tbody>
  55. </table>
  56. <dl class="details">
  57. <dt class="tag-returns"><strong>Returns:</strong> A group of meshes.</dt>
  58. </dl>
  59. </div>
  60. <h3 class="name name-method" id="~createMultiMaterialObject" translate="no">.<a href="#~createMultiMaterialObject">createMultiMaterialObject</a><span class="signature">( geometry : <span class="param-type">BufferGeometry</span>, materials : <span class="param-type">Array.&lt;Material></span> )</span><span class="type-signature"> : <a href="Group.html">Group</a></span> <span class="type-signature">(inner) </span></h3>
  61. <div class="method">
  62. <div class="description">
  63. <p>This function represents an alternative way to create 3D objects with multiple materials.
  64. Normally, <a href="BufferGeometry.html#groups">BufferGeometry#groups</a> are used which might introduce issues e.g. when
  65. exporting the object to a 3D format. This function accepts a geometry and an array of
  66. materials and creates for each material a mesh that is added to a group.</p>
  67. </div>
  68. <table class="params">
  69. <tbody>
  70. <tr>
  71. <td class="name"><code>geometry</code></td>
  72. <td class="description last"><p>The geometry.</p></td>
  73. </tr>
  74. <tr>
  75. <td class="name"><code>materials</code></td>
  76. <td class="description last"><p>An array of materials.</p></td>
  77. </tr>
  78. </tbody>
  79. </table>
  80. <dl class="details">
  81. <dt class="tag-returns"><strong>Returns:</strong> A group representing a multi-material object.</dt>
  82. </dl>
  83. </div>
  84. <h3 class="name name-method" id="~reduceVertices" translate="no">.<a href="#~reduceVertices">reduceVertices</a><span class="signature">( object : <span class="param-type">Object3D</span>, func : <span class="param-type">function</span>, initialValue : <span class="param-type">any</span> )</span><span class="type-signature"> : <a href="global.html#any">any</a></span> <span class="type-signature">(inner) </span></h3>
  85. <div class="method">
  86. <div class="description">
  87. <p>Executes a reducer function for each vertex of the given 3D object.
  88. <code>reduceVertices()</code> returns a single value: the function's accumulated result.</p>
  89. </div>
  90. <table class="params">
  91. <tbody>
  92. <tr>
  93. <td class="name"><code>object</code></td>
  94. <td class="description last"><p>The 3D object that should be processed. It must have a
  95. geometry with a <code>position</code> attribute.</p></td>
  96. </tr>
  97. <tr>
  98. <td class="name"><code>func</code></td>
  99. <td class="description last"><p>The reducer function. First argument
  100. is the current value, second argument the current vertex.</p></td>
  101. </tr>
  102. <tr>
  103. <td class="name"><code>initialValue</code></td>
  104. <td class="description last"><p>The initial value.</p></td>
  105. </tr>
  106. </tbody>
  107. </table>
  108. <dl class="details">
  109. <dt class="tag-returns"><strong>Returns:</strong> The result.</dt>
  110. </dl>
  111. </div>
  112. <h3 class="name name-method" id="~sortInstancedMesh" translate="no">.<a href="#~sortInstancedMesh">sortInstancedMesh</a><span class="signature">( mesh : <span class="param-type">InstancedMesh</span>, compareFn : <span class="param-type">function</span> )</span> <span class="type-signature">(inner) </span></h3>
  113. <div class="method">
  114. <div class="description">
  115. <p>Sorts the instances of the given instanced mesh.</p>
  116. </div>
  117. <table class="params">
  118. <tbody>
  119. <tr>
  120. <td class="name"><code>mesh</code></td>
  121. <td class="description last"><p>The instanced mesh to sort.</p></td>
  122. </tr>
  123. <tr>
  124. <td class="name"><code>compareFn</code></td>
  125. <td class="description last"><p>A custom compare function for the sort.</p></td>
  126. </tr>
  127. </tbody>
  128. </table>
  129. </div>
  130. <h3 class="name name-method" id="~traverseAncestorsGenerator" translate="no">.<a href="#~traverseAncestorsGenerator">traverseAncestorsGenerator</a><span class="signature">( object : <span class="param-type">Object3D</span> )</span><span class="type-signature"> : <a href="Object3D.html">Object3D</a></span> <span class="type-signature">(generator, inner) </span></h3>
  131. <div class="method">
  132. <div class="description">
  133. <p>Generator based alternative to <a href="Object3D.html#traverseAncestors">Object3D#traverseAncestors</a>.</p>
  134. </div>
  135. <table class="params">
  136. <tbody>
  137. <tr>
  138. <td class="name"><code>object</code></td>
  139. <td class="description last"><p>Object to traverse.</p></td>
  140. </tr>
  141. </tbody>
  142. </table>
  143. <h5>Yields:</h5>
  144. Objects that passed the filter condition.
  145. </div>
  146. <h3 class="name name-method" id="~traverseGenerator" translate="no">.<a href="#~traverseGenerator">traverseGenerator</a><span class="signature">( object : <span class="param-type">Object3D</span> )</span><span class="type-signature"> : <a href="Object3D.html">Object3D</a></span> <span class="type-signature">(generator, inner) </span></h3>
  147. <div class="method">
  148. <div class="description">
  149. <p>Generator based alternative to <a href="Object3D.html#traverse">Object3D#traverse</a>.</p>
  150. </div>
  151. <table class="params">
  152. <tbody>
  153. <tr>
  154. <td class="name"><code>object</code></td>
  155. <td class="description last"><p>Object to traverse.</p></td>
  156. </tr>
  157. </tbody>
  158. </table>
  159. <h5>Yields:</h5>
  160. Objects that passed the filter condition.
  161. </div>
  162. <h3 class="name name-method" id="~traverseVisibleGenerator" translate="no">.<a href="#~traverseVisibleGenerator">traverseVisibleGenerator</a><span class="signature">( object : <span class="param-type">Object3D</span> )</span><span class="type-signature"> : <a href="Object3D.html">Object3D</a></span> <span class="type-signature">(generator, inner) </span></h3>
  163. <div class="method">
  164. <div class="description">
  165. <p>Generator based alternative to <a href="Object3D.html#traverseVisible">Object3D#traverseVisible</a>.</p>
  166. </div>
  167. <table class="params">
  168. <tbody>
  169. <tr>
  170. <td class="name"><code>object</code></td>
  171. <td class="description last"><p>Object to traverse.</p></td>
  172. </tr>
  173. </tbody>
  174. </table>
  175. <h5>Yields:</h5>
  176. Objects that passed the filter condition.
  177. </div>
  178. <h2 class="subsection-title">Source</h2>
  179. <p>
  180. <a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/utils/SceneUtils.js" target="_blank" rel="noopener" translate="no">examples/jsm/utils/SceneUtils.js</a>
  181. </p>
  182. </article>
  183. </section>
  184. <script src="../scripts/linenumber.js"></script>
  185. <script src="../scripts/page.js"></script>
  186. </body>
  187. </html>
粤ICP备19079148号