ConvexObjectBreaker.html 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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">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"><code>minSizeForBreak</code></td>
  45. <td class="description last"><p>Min size a debris can have to break.<br/>Default is <code>1.4</code>.</p></td>
  46. </tr>
  47. <tr>
  48. <td class="name"><code>smallDelta</code></td>
  49. <td class="description last"><p>Max distance to consider that a point belongs to a plane.<br/>Default is <code>0.0001</code>.</p></td>
  50. </tr>
  51. </tbody>
  52. </table>
  53. </div>
  54. </div>
  55. <h2 class="subsection-title">Methods</h2>
  56. <h3 class="name name-method" id="cutByPlane" translate="no">.<a href="#cutByPlane">cutByPlane</a><span class="signature">( object : <span class="param-type">Object3D</span>, plane : <span class="param-type">Plane</span>, output : <span class="param-type">Object</span> )</span><span class="type-signature"> : number</span> </h3>
  57. <div class="method">
  58. <div class="description">
  59. <p>Subdivides the given 3D object into pieces by a plane.</p>
  60. </div>
  61. <table class="params">
  62. <tbody>
  63. <tr>
  64. <td class="name"><code>object</code></td>
  65. <td class="description last"><p>The 3D object to subdivide.</p></td>
  66. </tr>
  67. <tr>
  68. <td class="name"><code>plane</code></td>
  69. <td class="description last"><p>The plane to cut the 3D object.</p></td>
  70. </tr>
  71. <tr>
  72. <td class="name"><code>output</code></td>
  73. <td class="description last"><p>An object that stores the pieces.</p></td>
  74. </tr>
  75. </tbody>
  76. </table>
  77. <dl class="details">
  78. <dt class="tag-returns"><strong>Returns:</strong> The number of pieces.</dt>
  79. </dl>
  80. </div>
  81. <h3 class="name name-method" id="prepareBreakableObject" translate="no">.<a href="#prepareBreakableObject">prepareBreakableObject</a><span class="signature">( object : <span class="param-type">Object3D</span>, mass : <span class="param-type">number</span>, velocity : <span class="param-type">Vector3</span>, angularVelocity : <span class="param-type">Vector3</span>, breakable : <span class="param-type">boolean</span> )</span> </h3>
  82. <div class="method">
  83. <div class="description">
  84. <p>Must be called for all 3D objects that should be breakable.</p>
  85. </div>
  86. <table class="params">
  87. <tbody>
  88. <tr>
  89. <td class="name"><code>object</code></td>
  90. <td class="description last"><p>The 3D object. It must have a convex geometry.</p></td>
  91. </tr>
  92. <tr>
  93. <td class="name"><code>mass</code></td>
  94. <td class="description last"><p>The 3D object's mass in kg. Must be greater than <code>0</code>.</p></td>
  95. </tr>
  96. <tr>
  97. <td class="name"><code>velocity</code></td>
  98. <td class="description last"><p>The 3D object's velocity.</p></td>
  99. </tr>
  100. <tr>
  101. <td class="name"><code>angularVelocity</code></td>
  102. <td class="description last"><p>The 3D object's angular velocity.</p></td>
  103. </tr>
  104. <tr>
  105. <td class="name"><code>breakable</code></td>
  106. <td class="description last"><p>Whether the 3D object is breakable or not.</p></td>
  107. </tr>
  108. </tbody>
  109. </table>
  110. </div>
  111. <h3 class="name name-method" id="subdivideByImpact" translate="no">.<a href="#subdivideByImpact">subdivideByImpact</a><span class="signature">( object : <span class="param-type">Object3D</span>, pointOfImpact : <span class="param-type">Vector3</span>, normal : <span class="param-type">Vector3</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>
  112. <div class="method">
  113. <div class="description">
  114. <p>Subdivides the given 3D object into pieces by an impact (meaning another object hits
  115. the given 3D object at a certain surface point).</p>
  116. </div>
  117. <table class="params">
  118. <tbody>
  119. <tr>
  120. <td class="name"><code>object</code></td>
  121. <td class="description last"><p>The 3D object to subdivide.</p></td>
  122. </tr>
  123. <tr>
  124. <td class="name"><code>pointOfImpact</code></td>
  125. <td class="description last"><p>The point of impact.</p></td>
  126. </tr>
  127. <tr>
  128. <td class="name"><code>normal</code></td>
  129. <td class="description last"><p>The impact normal.</p></td>
  130. </tr>
  131. <tr>
  132. <td class="name"><code>maxRadialIterations</code></td>
  133. <td class="description last"><p>Iterations for radial cuts.</p></td>
  134. </tr>
  135. <tr>
  136. <td class="name"><code>maxRandomIterations</code></td>
  137. <td class="description last"><p>Max random iterations for not-radial cuts.</p></td>
  138. </tr>
  139. </tbody>
  140. </table>
  141. <dl class="details">
  142. <dt class="tag-returns"><strong>Returns:</strong> The array of pieces.</dt>
  143. </dl>
  144. </div>
  145. <h2 class="subsection-title">Source</h2>
  146. <p>
  147. <a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/misc/ConvexObjectBreaker.js" target="_blank" rel="noopener" translate="no">examples/jsm/misc/ConvexObjectBreaker.js</a>
  148. </p>
  149. </article>
  150. </section>
  151. <script src="../scripts/linenumber.js"></script>
  152. <script src="../scripts/page.js"></script>
  153. </body>
  154. </html>
粤ICP备19079148号