AmmoPhysics.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>AmmoPhysics - 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">AmmoPhysics</h1>
  13. <section>
  14. <header>
  15. <div class="class-description"><p>Can be used to include Ammo.js as a Physics engine into
  16. <code>three.js</code> apps. Make sure to include <code>ammo.wasm.js</code> first:</p>
  17. <p>It is then possible to initialize the API via:</p>
  18. <pre><code class="language-js">const physics = await AmmoPhysics();
  19. </code></pre></div>
  20. <h2>Code Example</h2>
  21. <div translate="no"><pre class="prettyprint source"><code>&lt;script src=&quot;jsm/libs/ammo.wasm.js&quot;>&lt;/script>
  22. </code></pre></div>
  23. </header>
  24. <article>
  25. <h2 class="subsection-title">Import</h2>
  26. <p><span translate="no">AmmoPhysics</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>
  27. <pre><code class="language-js">import { AmmoPhysics } from 'three/addons/physics/AmmoPhysics.js';</code></pre>
  28. <div class="container-overview">
  29. <div class="method">
  30. </div>
  31. </div>
  32. <h2 class="subsection-title">Methods</h2>
  33. <h3 class="name name-method" id="addMesh" translate="no">.<a href="#addMesh">addMesh</a><span class="signature">( mesh : <span class="param-type"><a href="Mesh.html">Mesh</a></span>, mass : <span class="param-type">number</span>, restitution : <span class="param-type">number</span> )</span> </h3>
  34. <div class="method">
  35. <div class="description">
  36. <p>Adds the given mesh to this physics simulation.</p>
  37. </div>
  38. <table class="params">
  39. <tbody>
  40. <tr>
  41. <td class="name">
  42. <strong>mesh</strong>
  43. </td>
  44. <td class="description last">
  45. <p>The mesh to add.</p>
  46. </td>
  47. </tr>
  48. <tr>
  49. <td class="name">
  50. <strong>mass</strong>
  51. </td>
  52. <td class="description last">
  53. <p>The mass in kg of the mesh.</p>
  54. <p>Default is <code>0</code>.</p>
  55. </td>
  56. </tr>
  57. <tr>
  58. <td class="name">
  59. <strong>restitution</strong>
  60. </td>
  61. <td class="description last">
  62. <p>The restitution of the mesh, usually from 0 to 1. Represents how &quot;bouncy&quot; objects are when they collide with each other.</p>
  63. <p>Default is <code>0</code>.</p>
  64. </td>
  65. </tr>
  66. </tbody>
  67. </table>
  68. </div>
  69. <h3 class="name name-method" id="addScene" translate="no">.<a href="#addScene">addScene</a><span class="signature">( scene : <span class="param-type"><a href="Object3D.html">Object3D</a></span> )</span> </h3>
  70. <div class="method">
  71. <div class="description">
  72. <p>Adds the given scene to this physics simulation. Only meshes with a
  73. <code>physics</code> object in their <a href="Object3D.html#userData">Object3D#userData</a> field will be honored.
  74. The object can be used to store the mass of the mesh. E.g.:</p>
  75. <pre><code class="language-js">box.userData.physics = { mass: 1 };
  76. </code></pre>
  77. </div>
  78. <table class="params">
  79. <tbody>
  80. <tr>
  81. <td class="name">
  82. <strong>scene</strong>
  83. </td>
  84. <td class="description last">
  85. <p>The scene or any type of 3D object to add.</p>
  86. </td>
  87. </tr>
  88. </tbody>
  89. </table>
  90. </div>
  91. <h3 class="name name-method" id="setMeshPosition" translate="no">.<a href="#setMeshPosition">setMeshPosition</a><span class="signature">( mesh : <span class="param-type"><a href="Mesh.html">Mesh</a></span>, position : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, index : <span class="param-type">number</span> )</span> </h3>
  92. <div class="method">
  93. <div class="description">
  94. <p>Set the position of the given mesh which is part of the physics simulation. Calling this
  95. method will reset the current simulated velocity of the mesh.</p>
  96. </div>
  97. <table class="params">
  98. <tbody>
  99. <tr>
  100. <td class="name">
  101. <strong>mesh</strong>
  102. </td>
  103. <td class="description last">
  104. <p>The mesh to update the position for.</p>
  105. </td>
  106. </tr>
  107. <tr>
  108. <td class="name">
  109. <strong>position</strong>
  110. </td>
  111. <td class="description last">
  112. <p>The new position.</p>
  113. </td>
  114. </tr>
  115. <tr>
  116. <td class="name">
  117. <strong>index</strong>
  118. </td>
  119. <td class="description last">
  120. <p>If the mesh is instanced, the index represents the instanced ID.</p>
  121. <p>Default is <code>0</code>.</p>
  122. </td>
  123. </tr>
  124. </tbody>
  125. </table>
  126. </div>
  127. <h2 class="subsection-title">Source</h2>
  128. <p>
  129. <a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/physics/AmmoPhysics.js" translate="no" target="_blank" rel="noopener">examples/jsm/physics/AmmoPhysics.js</a>
  130. </p>
  131. </article>
  132. </section>
  133. <script src="../scripts/linenumber.js"></script>
  134. <script src="../scripts/page.js"></script>
  135. </body>
  136. </html>
粤ICP备19079148号