JoltPhysics.html 5.2 KB

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