module-SceneUtils.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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" rel="noopener">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"><a href="InstancedMesh.html">InstancedMesh</a></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">
  34. <strong>instancedMesh</strong>
  35. </td>
  36. <td class="description last">
  37. <p>The instanced mesh.</p>
  38. </td>
  39. </tr>
  40. </tbody>
  41. </table>
  42. <dl class="details">
  43. <dt class="tag-returns"><strong>Returns:</strong> A group of meshes.</dt>
  44. </dl>
  45. </div>
  46. <h3 class="name name-method" id="~createMeshesFromMultiMaterialMesh" translate="no">.<a href="#~createMeshesFromMultiMaterialMesh">createMeshesFromMultiMaterialMesh</a><span class="signature">( mesh : <span class="param-type"><a href="Mesh.html">Mesh</a></span> )</span><span class="type-signature"> : <a href="Group.html">Group</a></span> <span class="type-signature">(inner) </span></h3>
  47. <div class="method">
  48. <div class="description">
  49. <p>This function creates a mesh for each geometry-group of the given multi-material mesh and
  50. adds it to a group.</p>
  51. </div>
  52. <table class="params">
  53. <tbody>
  54. <tr>
  55. <td class="name">
  56. <strong>mesh</strong>
  57. </td>
  58. <td class="description last">
  59. <p>The multi-material mesh.</p>
  60. </td>
  61. </tr>
  62. </tbody>
  63. </table>
  64. <dl class="details">
  65. <dt class="tag-returns"><strong>Returns:</strong> A group of meshes.</dt>
  66. </dl>
  67. </div>
  68. <h3 class="name name-method" id="~createMultiMaterialObject" translate="no">.<a href="#~createMultiMaterialObject">createMultiMaterialObject</a><span class="signature">( geometry : <span class="param-type"><a href="BufferGeometry.html">BufferGeometry</a></span>, materials : <span class="param-type">Array.&lt;<a href="Material.html">Material</a>></span> )</span><span class="type-signature"> : <a href="Group.html">Group</a></span> <span class="type-signature">(inner) </span></h3>
  69. <div class="method">
  70. <div class="description">
  71. <p>This function represents an alternative way to create 3D objects with multiple materials.
  72. Normally, <a href="BufferGeometry.html#groups">BufferGeometry#groups</a> are used which might introduce issues e.g. when
  73. exporting the object to a 3D format. This function accepts a geometry and an array of
  74. materials and creates for each material a mesh that is added to a group.</p>
  75. </div>
  76. <table class="params">
  77. <tbody>
  78. <tr>
  79. <td class="name">
  80. <strong>geometry</strong>
  81. </td>
  82. <td class="description last">
  83. <p>The geometry.</p>
  84. </td>
  85. </tr>
  86. <tr>
  87. <td class="name">
  88. <strong>materials</strong>
  89. </td>
  90. <td class="description last">
  91. <p>An array of materials.</p>
  92. </td>
  93. </tr>
  94. </tbody>
  95. </table>
  96. <dl class="details">
  97. <dt class="tag-returns"><strong>Returns:</strong> A group representing a multi-material object.</dt>
  98. </dl>
  99. </div>
  100. <h3 class="name name-method" id="~reduceVertices" translate="no">.<a href="#~reduceVertices">reduceVertices</a><span class="signature">( object : <span class="param-type"><a href="Object3D.html">Object3D</a></span>, func : <span class="param-type">function</span>, initialValue : <span class="param-type"><a href="global.html#any">any</a></span> )</span><span class="type-signature"> : <a href="global.html#any">any</a></span> <span class="type-signature">(inner) </span></h3>
  101. <div class="method">
  102. <div class="description">
  103. <p>Executes a reducer function for each vertex of the given 3D object.
  104. <code>reduceVertices()</code> returns a single value: the function's accumulated result.</p>
  105. </div>
  106. <table class="params">
  107. <tbody>
  108. <tr>
  109. <td class="name">
  110. <strong>object</strong>
  111. </td>
  112. <td class="description last">
  113. <p>The 3D object that should be processed. It must have a
  114. geometry with a <code>position</code> attribute.</p>
  115. </td>
  116. </tr>
  117. <tr>
  118. <td class="name">
  119. <strong>func</strong>
  120. </td>
  121. <td class="description last">
  122. <p>The reducer function. First argument
  123. is the current value, second argument the current vertex.</p>
  124. </td>
  125. </tr>
  126. <tr>
  127. <td class="name">
  128. <strong>initialValue</strong>
  129. </td>
  130. <td class="description last">
  131. <p>The initial value.</p>
  132. </td>
  133. </tr>
  134. </tbody>
  135. </table>
  136. <dl class="details">
  137. <dt class="tag-returns"><strong>Returns:</strong> The result.</dt>
  138. </dl>
  139. </div>
  140. <h3 class="name name-method" id="~sortInstancedMesh" translate="no">.<a href="#~sortInstancedMesh">sortInstancedMesh</a><span class="signature">( mesh : <span class="param-type"><a href="InstancedMesh.html">InstancedMesh</a></span>, compareFn : <span class="param-type">function</span> )</span> <span class="type-signature">(inner) </span></h3>
  141. <div class="method">
  142. <div class="description">
  143. <p>Sorts the instances of the given instanced mesh.</p>
  144. </div>
  145. <table class="params">
  146. <tbody>
  147. <tr>
  148. <td class="name">
  149. <strong>mesh</strong>
  150. </td>
  151. <td class="description last">
  152. <p>The instanced mesh to sort.</p>
  153. </td>
  154. </tr>
  155. <tr>
  156. <td class="name">
  157. <strong>compareFn</strong>
  158. </td>
  159. <td class="description last">
  160. <p>A custom compare function for the sort.</p>
  161. </td>
  162. </tr>
  163. </tbody>
  164. </table>
  165. </div>
  166. <h3 class="name name-method" id="~traverseAncestorsGenerator" translate="no">.<a href="#~traverseAncestorsGenerator">traverseAncestorsGenerator</a><span class="signature">( object : <span class="param-type"><a href="Object3D.html">Object3D</a></span> )</span><span class="type-signature"> : <a href="Object3D.html">Object3D</a></span> <span class="type-signature">(generator, inner) </span></h3>
  167. <div class="method">
  168. <div class="description">
  169. <p>Generator based alternative to <a href="Object3D.html#traverseAncestors">Object3D#traverseAncestors</a>.</p>
  170. </div>
  171. <table class="params">
  172. <tbody>
  173. <tr>
  174. <td class="name">
  175. <strong>object</strong>
  176. </td>
  177. <td class="description last">
  178. <p>Object to traverse.</p>
  179. </td>
  180. </tr>
  181. </tbody>
  182. </table>
  183. <h5>Yields:</h5>
  184. Objects that passed the filter condition.
  185. </div>
  186. <h3 class="name name-method" id="~traverseGenerator" translate="no">.<a href="#~traverseGenerator">traverseGenerator</a><span class="signature">( object : <span class="param-type"><a href="Object3D.html">Object3D</a></span> )</span><span class="type-signature"> : <a href="Object3D.html">Object3D</a></span> <span class="type-signature">(generator, inner) </span></h3>
  187. <div class="method">
  188. <div class="description">
  189. <p>Generator based alternative to <a href="Object3D.html#traverse">Object3D#traverse</a>.</p>
  190. </div>
  191. <table class="params">
  192. <tbody>
  193. <tr>
  194. <td class="name">
  195. <strong>object</strong>
  196. </td>
  197. <td class="description last">
  198. <p>Object to traverse.</p>
  199. </td>
  200. </tr>
  201. </tbody>
  202. </table>
  203. <h5>Yields:</h5>
  204. Objects that passed the filter condition.
  205. </div>
  206. <h3 class="name name-method" id="~traverseVisibleGenerator" translate="no">.<a href="#~traverseVisibleGenerator">traverseVisibleGenerator</a><span class="signature">( object : <span class="param-type"><a href="Object3D.html">Object3D</a></span> )</span><span class="type-signature"> : <a href="Object3D.html">Object3D</a></span> <span class="type-signature">(generator, inner) </span></h3>
  207. <div class="method">
  208. <div class="description">
  209. <p>Generator based alternative to <a href="Object3D.html#traverseVisible">Object3D#traverseVisible</a>.</p>
  210. </div>
  211. <table class="params">
  212. <tbody>
  213. <tr>
  214. <td class="name">
  215. <strong>object</strong>
  216. </td>
  217. <td class="description last">
  218. <p>Object to traverse.</p>
  219. </td>
  220. </tr>
  221. </tbody>
  222. </table>
  223. <h5>Yields:</h5>
  224. Objects that passed the filter condition.
  225. </div>
  226. <h2 class="subsection-title">Source</h2>
  227. <p>
  228. <a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/utils/SceneUtils.js" translate="no" target="_blank" rel="noopener">examples/jsm/utils/SceneUtils.js</a>
  229. </p>
  230. </article>
  231. </section>
  232. <script src="../scripts/linenumber.js"></script>
  233. <script src="../scripts/page.js"></script>
  234. </body>
  235. </html>
粤ICP备19079148号