JoltPhysics.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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">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">Mesh</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"><code>mesh</code></td>
  41. <td class="description last"><p>The mesh to add.</p></td>
  42. </tr>
  43. <tr>
  44. <td class="name"><code>mass</code></td>
  45. <td class="description last"><p>The mass in kg of the mesh.<br/>Default is <code>0</code>.</p></td>
  46. </tr>
  47. <tr>
  48. <td class="name"><code>restitution</code></td>
  49. <td class="description last"><p>The restitution/friction of the mesh.<br/>Default is <code>0</code>.</p></td>
  50. </tr>
  51. </tbody>
  52. </table>
  53. </div>
  54. <h3 class="name name-method" id="addScene" translate="no">.<a href="#addScene">addScene</a><span class="signature">( scene : <span class="param-type">Object3D</span> )</span> </h3>
  55. <div class="method">
  56. <div class="description">
  57. <p>Adds the given scene to this physics simulation. Only meshes with a
  58. <code>physics</code> object in their <a href="Object3D.html#userData">Object3D#userData</a> field will be honored.
  59. The object can be used to store the mass and restitution of the mesh. E.g.:</p>
  60. <pre><code class="language-js">box.userData.physics = { mass: 1, restitution: 0 };
  61. </code></pre>
  62. </div>
  63. <table class="params">
  64. <tbody>
  65. <tr>
  66. <td class="name"><code>scene</code></td>
  67. <td class="description last"><p>The scene or any type of 3D object to add.</p></td>
  68. </tr>
  69. </tbody>
  70. </table>
  71. </div>
  72. <h3 class="name name-method" id="setMeshPosition" translate="no">.<a href="#setMeshPosition">setMeshPosition</a><span class="signature">( mesh : <span class="param-type">Mesh</span>, position : <span class="param-type">Vector3</span>, index : <span class="param-type">number</span> )</span> </h3>
  73. <div class="method">
  74. <div class="description">
  75. <p>Set the position of the given mesh which is part of the physics simulation. Calling this
  76. method will reset the current simulated velocity of the mesh.</p>
  77. </div>
  78. <table class="params">
  79. <tbody>
  80. <tr>
  81. <td class="name"><code>mesh</code></td>
  82. <td class="description last"><p>The mesh to update the position for.</p></td>
  83. </tr>
  84. <tr>
  85. <td class="name"><code>position</code></td>
  86. <td class="description last"><p>The new position.</p></td>
  87. </tr>
  88. <tr>
  89. <td class="name"><code>index</code></td>
  90. <td class="description last"><p>If the mesh is instanced, the index represents the instanced ID.<br/>Default is <code>0</code>.</p></td>
  91. </tr>
  92. </tbody>
  93. </table>
  94. </div>
  95. <h2 class="subsection-title">Source</h2>
  96. <p>
  97. <a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/physics/JoltPhysics.js" target="_blank" rel="noopener" translate="no">examples/jsm/physics/JoltPhysics.js</a>
  98. </p>
  99. </article>
  100. </section>
  101. <script src="../scripts/linenumber.js"></script>
  102. <script src="../scripts/page.js"></script>
  103. </body>
  104. </html>
粤ICP备19079148号