ConvexObjectBreaker.html 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>ConvexObjectBreaker - 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">ConvexObjectBreaker</h1>
  13. <section>
  14. <header>
  15. <div class="class-description"><p>This class can be used to subdivide a convex Geometry object into pieces.</p>
  16. <p>Use the function prepareBreakableObject to prepare a Mesh object to be broken.
  17. Then, call the various functions to subdivide the object (subdivideByImpact, cutByPlane).
  18. Sub-objects that are product of subdivision don't need prepareBreakableObject to be called on them.</p>
  19. <p>Requisites for the object:</p>
  20. <ul>
  21. <li>Mesh object must have a buffer geometry and a material.</li>
  22. <li>Vertex normals must be planar (not smoothed).</li>
  23. <li>The geometry must be convex (this is not checked in the library). You can create convex
  24. geometries with <a href="ConvexGeometry.html">ConvexGeometry</a>. The <a href="BoxGeometry.html">BoxGeometry</a>, <a href="SphereGeometry.html">SphereGeometry</a> and other
  25. convex primitives can also be used.</li>
  26. </ul>
  27. <p>Note: This lib adds member variables to object's userData member (see prepareBreakableObject function)
  28. Use with caution and read the code when using with other libs.</p></div>
  29. </header>
  30. <article>
  31. <h2 class="subsection-title">Import</h2>
  32. <p><span translate="no">ConvexObjectBreaker</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>
  33. <pre><code class="language-js">import { ConvexObjectBreaker } from 'three/addons/misc/ConvexObjectBreaker.js';</code></pre>
  34. <div class="container-overview">
  35. <h2>Constructor</h2>
  36. <h3 class="name name-method" id="ConvexObjectBreaker" translate="no">new <a href="#ConvexObjectBreaker">ConvexObjectBreaker</a><span class="signature">( minSizeForBreak : <span class="param-type">number</span>, smallDelta : <span class="param-type">number</span> )</span> </h3>
  37. <div class="method">
  38. <div class="description">
  39. <p>Constructs a new convex object breaker.</p>
  40. </div>
  41. <table class="params">
  42. <tbody>
  43. <tr>
  44. <td class="name">
  45. <strong>minSizeForBreak</strong>
  46. </td>
  47. <td class="description last">
  48. <p>Min size a debris can have to break.</p>
  49. <p>Default is <code>1.4</code>.</p>
  50. </td>
  51. </tr>
  52. <tr>
  53. <td class="name">
  54. <strong>smallDelta</strong>
  55. </td>
  56. <td class="description last">
  57. <p>Max distance to consider that a point belongs to a plane.</p>
  58. <p>Default is <code>0.0001</code>.</p>
  59. </td>
  60. </tr>
  61. </tbody>
  62. </table>
  63. </div>
  64. </div>
  65. <h2 class="subsection-title">Methods</h2>
  66. <h3 class="name name-method" id="cutByPlane" translate="no">.<a href="#cutByPlane">cutByPlane</a><span class="signature">( object : <span class="param-type"><a href="Object3D.html">Object3D</a></span>, plane : <span class="param-type"><a href="Plane.html">Plane</a></span>, output : <span class="param-type">Object</span> )</span><span class="type-signature"> : number</span> </h3>
  67. <div class="method">
  68. <div class="description">
  69. <p>Subdivides the given 3D object into pieces by a plane.</p>
  70. </div>
  71. <table class="params">
  72. <tbody>
  73. <tr>
  74. <td class="name">
  75. <strong>object</strong>
  76. </td>
  77. <td class="description last">
  78. <p>The 3D object to subdivide.</p>
  79. </td>
  80. </tr>
  81. <tr>
  82. <td class="name">
  83. <strong>plane</strong>
  84. </td>
  85. <td class="description last">
  86. <p>The plane to cut the 3D object.</p>
  87. </td>
  88. </tr>
  89. <tr>
  90. <td class="name">
  91. <strong>output</strong>
  92. </td>
  93. <td class="description last">
  94. <p>An object that stores the pieces.</p>
  95. </td>
  96. </tr>
  97. </tbody>
  98. </table>
  99. <dl class="details">
  100. <dt class="tag-returns"><strong>Returns:</strong> The number of pieces.</dt>
  101. </dl>
  102. </div>
  103. <h3 class="name name-method" id="prepareBreakableObject" translate="no">.<a href="#prepareBreakableObject">prepareBreakableObject</a><span class="signature">( object : <span class="param-type"><a href="Object3D.html">Object3D</a></span>, mass : <span class="param-type">number</span>, velocity : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, angularVelocity : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, breakable : <span class="param-type">boolean</span> )</span> </h3>
  104. <div class="method">
  105. <div class="description">
  106. <p>Must be called for all 3D objects that should be breakable.</p>
  107. </div>
  108. <table class="params">
  109. <tbody>
  110. <tr>
  111. <td class="name">
  112. <strong>object</strong>
  113. </td>
  114. <td class="description last">
  115. <p>The 3D object. It must have a convex geometry.</p>
  116. </td>
  117. </tr>
  118. <tr>
  119. <td class="name">
  120. <strong>mass</strong>
  121. </td>
  122. <td class="description last">
  123. <p>The 3D object's mass in kg. Must be greater than <code>0</code>.</p>
  124. </td>
  125. </tr>
  126. <tr>
  127. <td class="name">
  128. <strong>velocity</strong>
  129. </td>
  130. <td class="description last">
  131. <p>The 3D object's velocity.</p>
  132. </td>
  133. </tr>
  134. <tr>
  135. <td class="name">
  136. <strong>angularVelocity</strong>
  137. </td>
  138. <td class="description last">
  139. <p>The 3D object's angular velocity.</p>
  140. </td>
  141. </tr>
  142. <tr>
  143. <td class="name">
  144. <strong>breakable</strong>
  145. </td>
  146. <td class="description last">
  147. <p>Whether the 3D object is breakable or not.</p>
  148. </td>
  149. </tr>
  150. </tbody>
  151. </table>
  152. </div>
  153. <h3 class="name name-method" id="subdivideByImpact" translate="no">.<a href="#subdivideByImpact">subdivideByImpact</a><span class="signature">( object : <span class="param-type"><a href="Object3D.html">Object3D</a></span>, pointOfImpact : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, normal : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, maxRadialIterations : <span class="param-type">number</span>, maxRandomIterations : <span class="param-type">number</span> )</span><span class="type-signature"> : Array.&lt;<a href="Object3D.html">Object3D</a>></span> </h3>
  154. <div class="method">
  155. <div class="description">
  156. <p>Subdivides the given 3D object into pieces by an impact (meaning another object hits
  157. the given 3D object at a certain surface point).</p>
  158. </div>
  159. <table class="params">
  160. <tbody>
  161. <tr>
  162. <td class="name">
  163. <strong>object</strong>
  164. </td>
  165. <td class="description last">
  166. <p>The 3D object to subdivide.</p>
  167. </td>
  168. </tr>
  169. <tr>
  170. <td class="name">
  171. <strong>pointOfImpact</strong>
  172. </td>
  173. <td class="description last">
  174. <p>The point of impact.</p>
  175. </td>
  176. </tr>
  177. <tr>
  178. <td class="name">
  179. <strong>normal</strong>
  180. </td>
  181. <td class="description last">
  182. <p>The impact normal.</p>
  183. </td>
  184. </tr>
  185. <tr>
  186. <td class="name">
  187. <strong>maxRadialIterations</strong>
  188. </td>
  189. <td class="description last">
  190. <p>Iterations for radial cuts.</p>
  191. </td>
  192. </tr>
  193. <tr>
  194. <td class="name">
  195. <strong>maxRandomIterations</strong>
  196. </td>
  197. <td class="description last">
  198. <p>Max random iterations for not-radial cuts.</p>
  199. </td>
  200. </tr>
  201. </tbody>
  202. </table>
  203. <dl class="details">
  204. <dt class="tag-returns"><strong>Returns:</strong> The array of pieces.</dt>
  205. </dl>
  206. </div>
  207. <h2 class="subsection-title">Source</h2>
  208. <p>
  209. <a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/misc/ConvexObjectBreaker.js" translate="no" target="_blank" rel="noopener">examples/jsm/misc/ConvexObjectBreaker.js</a>
  210. </p>
  211. </article>
  212. </section>
  213. <script src="../scripts/linenumber.js"></script>
  214. <script src="../scripts/page.js"></script>
  215. </body>
  216. </html>
粤ICP备19079148号