RapierPhysics.html 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>RapierPhysics - 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">RapierPhysics</h1>
  13. <section>
  14. <header>
  15. <div class="class-description"><p>Can be used to include Rapier as a Physics engine into
  16. <code>three.js</code> apps. The API can be initialized via:</p>
  17. <p>The component automatically imports Rapier 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 RapierPhysics();
  21. </code></pre></div>
  22. </header>
  23. <article>
  24. <h2 class="subsection-title">Import</h2>
  25. <p><span translate="no">RapierPhysics</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 { RapierPhysics } from 'three/addons/physics/RapierPhysics.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="addHeightfield" translate="no">.<a href="#addHeightfield">addHeightfield</a><span class="signature">( mesh : <span class="param-type"><a href="Mesh.html">Mesh</a></span>, width : <span class="param-type">number</span>, depth : <span class="param-type">number</span>, heights : <span class="param-type">Float32Array</span>, scale : <span class="param-type">Object</span> )</span><span class="type-signature"> : RigidBody</span> </h3>
  33. <div class="method">
  34. <div class="description">
  35. <p>Adds a heightfield terrain to the 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 Three.js mesh representing the terrain.</p>
  45. </td>
  46. </tr>
  47. <tr>
  48. <td class="name">
  49. <strong>width</strong>
  50. </td>
  51. <td class="description last">
  52. <p>The number of vertices along the width (x-axis) of the heightfield.</p>
  53. </td>
  54. </tr>
  55. <tr>
  56. <td class="name">
  57. <strong>depth</strong>
  58. </td>
  59. <td class="description last">
  60. <p>The number of vertices along the depth (z-axis) of the heightfield.</p>
  61. </td>
  62. </tr>
  63. <tr>
  64. <td class="name">
  65. <strong>heights</strong>
  66. </td>
  67. <td class="description last">
  68. <p>Array of height values for each vertex in the heightfield.</p>
  69. </td>
  70. </tr>
  71. <tr>
  72. <td class="name">
  73. <strong>scale</strong>
  74. </td>
  75. <td class="description last">
  76. <p>Scale factors for the heightfield dimensions.</p>
  77. <table class="params">
  78. <tbody>
  79. <tr>
  80. <td class="name">
  81. <strong>x</strong>
  82. </td>
  83. <td class="description last">
  84. <p>Scale factor for width.</p>
  85. </td>
  86. </tr>
  87. <tr>
  88. <td class="name">
  89. <strong>y</strong>
  90. </td>
  91. <td class="description last">
  92. <p>Scale factor for height.</p>
  93. </td>
  94. </tr>
  95. <tr>
  96. <td class="name">
  97. <strong>z</strong>
  98. </td>
  99. <td class="description last">
  100. <p>Scale factor for depth.</p>
  101. </td>
  102. </tr>
  103. </tbody>
  104. </table>
  105. </td>
  106. </tr>
  107. </tbody>
  108. </table>
  109. <dl class="details">
  110. <dt class="tag-returns"><strong>Returns:</strong> The created Rapier rigid body for the heightfield.</dt>
  111. </dl>
  112. </div>
  113. <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>
  114. <div class="method">
  115. <div class="description">
  116. <p>Adds the given mesh to this physics simulation.</p>
  117. </div>
  118. <table class="params">
  119. <tbody>
  120. <tr>
  121. <td class="name">
  122. <strong>mesh</strong>
  123. </td>
  124. <td class="description last">
  125. <p>The mesh to add.</p>
  126. </td>
  127. </tr>
  128. <tr>
  129. <td class="name">
  130. <strong>mass</strong>
  131. </td>
  132. <td class="description last">
  133. <p>The mass in kg of the mesh.</p>
  134. <p>Default is <code>0</code>.</p>
  135. </td>
  136. </tr>
  137. <tr>
  138. <td class="name">
  139. <strong>restitution</strong>
  140. </td>
  141. <td class="description last">
  142. <p>The restitution/friction of the mesh.</p>
  143. <p>Default is <code>0</code>.</p>
  144. </td>
  145. </tr>
  146. </tbody>
  147. </table>
  148. </div>
  149. <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>
  150. <div class="method">
  151. <div class="description">
  152. <p>Adds the given scene to this physics simulation. Only meshes with a
  153. <code>physics</code> object in their <a href="Object3D.html#userData">Object3D#userData</a> field will be honored.
  154. The object can be used to store the mass and restitution of the mesh. E.g.:</p>
  155. <pre><code class="language-js">box.userData.physics = { mass: 1, restitution: 0 };
  156. </code></pre>
  157. </div>
  158. <table class="params">
  159. <tbody>
  160. <tr>
  161. <td class="name">
  162. <strong>scene</strong>
  163. </td>
  164. <td class="description last">
  165. <p>The scene or any type of 3D object to add.</p>
  166. </td>
  167. </tr>
  168. </tbody>
  169. </table>
  170. </div>
  171. <h3 class="name name-method" id="removeMesh" translate="no">.<a href="#removeMesh">removeMesh</a><span class="signature">( mesh : <span class="param-type"><a href="Mesh.html">Mesh</a></span> )</span> </h3>
  172. <div class="method">
  173. <div class="description">
  174. <p>Removes the given mesh from this physics simulation.</p>
  175. </div>
  176. <table class="params">
  177. <tbody>
  178. <tr>
  179. <td class="name">
  180. <strong>mesh</strong>
  181. </td>
  182. <td class="description last">
  183. <p>The mesh to remove.</p>
  184. </td>
  185. </tr>
  186. </tbody>
  187. </table>
  188. </div>
  189. <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>
  190. <div class="method">
  191. <div class="description">
  192. <p>Set the position of the given mesh which is part of the physics simulation. Calling this
  193. method will reset the current simulated velocity of the mesh.</p>
  194. </div>
  195. <table class="params">
  196. <tbody>
  197. <tr>
  198. <td class="name">
  199. <strong>mesh</strong>
  200. </td>
  201. <td class="description last">
  202. <p>The mesh to update the position for.</p>
  203. </td>
  204. </tr>
  205. <tr>
  206. <td class="name">
  207. <strong>position</strong>
  208. </td>
  209. <td class="description last">
  210. <p>The new position.</p>
  211. </td>
  212. </tr>
  213. <tr>
  214. <td class="name">
  215. <strong>index</strong>
  216. </td>
  217. <td class="description last">
  218. <p>If the mesh is instanced, the index represents the instanced ID.</p>
  219. <p>Default is <code>0</code>.</p>
  220. </td>
  221. </tr>
  222. </tbody>
  223. </table>
  224. </div>
  225. <h3 class="name name-method" id="setMeshVelocity" translate="no">.<a href="#setMeshVelocity">setMeshVelocity</a><span class="signature">( mesh : <span class="param-type"><a href="Mesh.html">Mesh</a></span>, velocity : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, index : <span class="param-type">number</span> )</span> </h3>
  226. <div class="method">
  227. <div class="description">
  228. <p>Set the velocity of the given mesh which is part of the physics simulation.</p>
  229. </div>
  230. <table class="params">
  231. <tbody>
  232. <tr>
  233. <td class="name">
  234. <strong>mesh</strong>
  235. </td>
  236. <td class="description last">
  237. <p>The mesh to update the velocity for.</p>
  238. </td>
  239. </tr>
  240. <tr>
  241. <td class="name">
  242. <strong>velocity</strong>
  243. </td>
  244. <td class="description last">
  245. <p>The new velocity.</p>
  246. </td>
  247. </tr>
  248. <tr>
  249. <td class="name">
  250. <strong>index</strong>
  251. </td>
  252. <td class="description last">
  253. <p>If the mesh is instanced, the index represents the instanced ID.</p>
  254. <p>Default is <code>0</code>.</p>
  255. </td>
  256. </tr>
  257. </tbody>
  258. </table>
  259. </div>
  260. <h2 class="subsection-title">Source</h2>
  261. <p>
  262. <a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/physics/RapierPhysics.js" translate="no" target="_blank" rel="noopener">examples/jsm/physics/RapierPhysics.js</a>
  263. </p>
  264. </article>
  265. </section>
  266. <script src="../scripts/linenumber.js"></script>
  267. <script src="../scripts/page.js"></script>
  268. </body>
  269. </html>
粤ICP备19079148号