OBB.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>OBB - 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">OBB</h1>
  13. <section>
  14. <header>
  15. <div class="class-description"><p>Represents an oriented bounding box (OBB) in 3D space.</p></div>
  16. </header>
  17. <article>
  18. <h2 class="subsection-title">Import</h2>
  19. <p><span translate="no">OBB</span> is an addon, and must be imported explicitly, see <a href="https://threejs.org/manual/#en/installation" target="_blank">Installation#Addons</a>.</p>
  20. <pre><code class="language-js">import { OBB } from 'three/addons/math/OBB.js';</code></pre>
  21. <div class="container-overview">
  22. <h2>Constructor</h2>
  23. <h3 class="name name-method" id="OBB" translate="no">new <a href="#OBB">OBB</a><span class="signature">( center : <span class="param-type">Vector3</span>, halfSize : <span class="param-type">Vector3</span>, rotation : <span class="param-type">Matrix3</span> )</span> </h3>
  24. <div class="method">
  25. <div class="description">
  26. <p>Constructs a new OBB.</p>
  27. </div>
  28. <table class="params">
  29. <tbody>
  30. <tr>
  31. <td class="name"><code>center</code></td>
  32. <td class="description last"><p>The center of the OBB.</p></td>
  33. </tr>
  34. <tr>
  35. <td class="name"><code>halfSize</code></td>
  36. <td class="description last"><p>Positive halfwidth extents of the OBB along each axis.</p></td>
  37. </tr>
  38. <tr>
  39. <td class="name"><code>rotation</code></td>
  40. <td class="description last"><p>The rotation of the OBB.</p></td>
  41. </tr>
  42. </tbody>
  43. </table>
  44. </div>
  45. </div>
  46. <h2 class="subsection-title">Properties</h2>
  47. <div class="member">
  48. <h3 class="name" id="center" translate="no">.<a href="#center">center</a><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
  49. <div class="description">
  50. <p>The center of the OBB.</p>
  51. </div>
  52. </div>
  53. <div class="member">
  54. <h3 class="name" id="halfSize" translate="no">.<a href="#halfSize">halfSize</a><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
  55. <div class="description">
  56. <p>Positive halfwidth extents of the OBB along each axis.</p>
  57. </div>
  58. </div>
  59. <div class="member">
  60. <h3 class="name" id="rotation" translate="no">.<a href="#rotation">rotation</a><span class="type-signature"> : <a href="Matrix3.html">Matrix3</a></span> </h3>
  61. <div class="description">
  62. <p>The rotation of the OBB.</p>
  63. </div>
  64. </div>
  65. <h2 class="subsection-title">Methods</h2>
  66. <h3 class="name name-method" id="applyMatrix4" translate="no">.<a href="#applyMatrix4">applyMatrix4</a><span class="signature">( matrix : <span class="param-type">Matrix4</span> )</span><span class="type-signature"> : <a href="OBB.html">OBB</a></span> </h3>
  67. <div class="method">
  68. <div class="description">
  69. <p>Applies the given transformation matrix to this OBB. This method can be
  70. used to transform the bounding volume with the world matrix of a 3D object
  71. in order to keep both entities in sync.</p>
  72. </div>
  73. <table class="params">
  74. <tbody>
  75. <tr>
  76. <td class="name"><code>matrix</code></td>
  77. <td class="description last"><p>The matrix to apply.</p></td>
  78. </tr>
  79. </tbody>
  80. </table>
  81. <dl class="details">
  82. <dt class="tag-returns"><strong>Returns:</strong> A reference of this OBB.</dt>
  83. </dl>
  84. </div>
  85. <h3 class="name name-method" id="clampPoint" translate="no">.<a href="#clampPoint">clampPoint</a><span class="signature">( point : <span class="param-type">Vector3</span>, target : <span class="param-type">Vector3</span> )</span><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
  86. <div class="method">
  87. <div class="description">
  88. <p>Clamps the given point within the bounds of this OBB.</p>
  89. </div>
  90. <table class="params">
  91. <tbody>
  92. <tr>
  93. <td class="name"><code>point</code></td>
  94. <td class="description last"><p>The point that should be clamped within the bounds of this OBB.</p></td>
  95. </tr>
  96. <tr>
  97. <td class="name"><code>target</code></td>
  98. <td class="description last"><p>The target vector that is used to store the method's result.</p></td>
  99. </tr>
  100. </tbody>
  101. </table>
  102. <dl class="details">
  103. <dt class="tag-returns"><strong>Returns:</strong> <ul>
  104. <li>The clamped point.</li>
  105. </ul></dt>
  106. </dl>
  107. </div>
  108. <h3 class="name name-method" id="clone" translate="no">.<a href="#clone">clone</a><span class="signature">()</span><span class="type-signature"> : <a href="OBB.html">OBB</a></span> </h3>
  109. <div class="method">
  110. <div class="description">
  111. <p>Returns a new OBB with copied values from this instance.</p>
  112. </div>
  113. <dl class="details">
  114. <dt class="tag-returns"><strong>Returns:</strong> A clone of this instance.</dt>
  115. </dl>
  116. </div>
  117. <h3 class="name name-method" id="containsPoint" translate="no">.<a href="#containsPoint">containsPoint</a><span class="signature">( point : <span class="param-type">Vector3</span> )</span><span class="type-signature"> : boolean</span> </h3>
  118. <div class="method">
  119. <div class="description">
  120. <p>Returns <code>true</code> if the given point lies within this OBB.</p>
  121. </div>
  122. <table class="params">
  123. <tbody>
  124. <tr>
  125. <td class="name"><code>point</code></td>
  126. <td class="description last"><p>The point to test.</p></td>
  127. </tr>
  128. </tbody>
  129. </table>
  130. <dl class="details">
  131. <dt class="tag-returns"><strong>Returns:</strong> <ul>
  132. <li>Whether the given point lies within this OBB or not.</li>
  133. </ul></dt>
  134. </dl>
  135. </div>
  136. <h3 class="name name-method" id="copy" translate="no">.<a href="#copy">copy</a><span class="signature">( obb : <span class="param-type">OBB</span> )</span><span class="type-signature"> : <a href="OBB.html">OBB</a></span> </h3>
  137. <div class="method">
  138. <div class="description">
  139. <p>Copies the values of the given OBB to this instance.</p>
  140. </div>
  141. <table class="params">
  142. <tbody>
  143. <tr>
  144. <td class="name"><code>obb</code></td>
  145. <td class="description last"><p>The OBB to copy.</p></td>
  146. </tr>
  147. </tbody>
  148. </table>
  149. <dl class="details">
  150. <dt class="tag-returns"><strong>Returns:</strong> A reference to this OBB.</dt>
  151. </dl>
  152. </div>
  153. <h3 class="name name-method" id="equals" translate="no">.<a href="#equals">equals</a><span class="signature">( obb : <span class="param-type">OBB</span> )</span><span class="type-signature"> : boolean</span> </h3>
  154. <div class="method">
  155. <div class="description">
  156. <p>Returns <code>true</code> if the given OBB is equal to this OBB.</p>
  157. </div>
  158. <table class="params">
  159. <tbody>
  160. <tr>
  161. <td class="name"><code>obb</code></td>
  162. <td class="description last"><p>The OBB to test.</p></td>
  163. </tr>
  164. </tbody>
  165. </table>
  166. <dl class="details">
  167. <dt class="tag-returns"><strong>Returns:</strong> Whether the given OBB is equal to this OBB or not.</dt>
  168. </dl>
  169. </div>
  170. <h3 class="name name-method" id="fromBox3" translate="no">.<a href="#fromBox3">fromBox3</a><span class="signature">( box3 : <span class="param-type">Box3</span> )</span><span class="type-signature"> : <a href="OBB.html">OBB</a></span> </h3>
  171. <div class="method">
  172. <div class="description">
  173. <p>Defines an OBB based on the given AABB.</p>
  174. </div>
  175. <table class="params">
  176. <tbody>
  177. <tr>
  178. <td class="name"><code>box3</code></td>
  179. <td class="description last"><p>The AABB to setup the OBB from.</p></td>
  180. </tr>
  181. </tbody>
  182. </table>
  183. <dl class="details">
  184. <dt class="tag-returns"><strong>Returns:</strong> A reference of this OBB.</dt>
  185. </dl>
  186. </div>
  187. <h3 class="name name-method" id="getSize" translate="no">.<a href="#getSize">getSize</a><span class="signature">( target : <span class="param-type">Vector3</span> )</span><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
  188. <div class="method">
  189. <div class="description">
  190. <p>Returns the size of this OBB.</p>
  191. </div>
  192. <table class="params">
  193. <tbody>
  194. <tr>
  195. <td class="name"><code>target</code></td>
  196. <td class="description last"><p>The target vector that is used to store the method's result.</p></td>
  197. </tr>
  198. </tbody>
  199. </table>
  200. <dl class="details">
  201. <dt class="tag-returns"><strong>Returns:</strong> The size.</dt>
  202. </dl>
  203. </div>
  204. <h3 class="name name-method" id="intersectRay" translate="no">.<a href="#intersectRay">intersectRay</a><span class="signature">( ray : <span class="param-type">Ray</span>, target : <span class="param-type">Vector3</span> )</span><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
  205. <div class="method">
  206. <div class="description">
  207. <p>Performs a ray/OBB intersection test and stores the intersection point
  208. in the given 3D vector.</p>
  209. </div>
  210. <table class="params">
  211. <tbody>
  212. <tr>
  213. <td class="name"><code>ray</code></td>
  214. <td class="description last"><p>The ray to test.</p></td>
  215. </tr>
  216. <tr>
  217. <td class="name"><code>target</code></td>
  218. <td class="description last"><p>The target vector that is used to store the method's result.</p></td>
  219. </tr>
  220. </tbody>
  221. </table>
  222. <dl class="details">
  223. <dt class="tag-returns"><strong>Returns:</strong> The intersection point. If no intersection is detected, <code>null</code> is returned.</dt>
  224. </dl>
  225. </div>
  226. <h3 class="name name-method" id="intersectsBox3" translate="no">.<a href="#intersectsBox3">intersectsBox3</a><span class="signature">( box3 : <span class="param-type">Box3</span> )</span><span class="type-signature"> : boolean</span> </h3>
  227. <div class="method">
  228. <div class="description">
  229. <p>Returns <code>true</code> if the given AABB intersects this OBB.</p>
  230. </div>
  231. <table class="params">
  232. <tbody>
  233. <tr>
  234. <td class="name"><code>box3</code></td>
  235. <td class="description last"><p>The AABB to test.</p></td>
  236. </tr>
  237. </tbody>
  238. </table>
  239. <dl class="details">
  240. <dt class="tag-returns"><strong>Returns:</strong> <ul>
  241. <li>Whether the given AABB intersects this OBB or not.</li>
  242. </ul></dt>
  243. </dl>
  244. </div>
  245. <h3 class="name name-method" id="intersectsOBB" translate="no">.<a href="#intersectsOBB">intersectsOBB</a><span class="signature">( obb : <span class="param-type">OBB</span>, epsilon : <span class="param-type">number</span> )</span><span class="type-signature"> : boolean</span> </h3>
  246. <div class="method">
  247. <div class="description">
  248. <p>Returns <code>true</code> if the given OBB intersects this OBB.</p>
  249. </div>
  250. <table class="params">
  251. <tbody>
  252. <tr>
  253. <td class="name"><code>obb</code></td>
  254. <td class="description last"><p>The OBB to test.</p></td>
  255. </tr>
  256. <tr>
  257. <td class="name"><code>epsilon</code></td>
  258. <td class="description last"><p>A small value to prevent arithmetic errors.<br/>Default is <code>Number.EPSILON</code>.</p></td>
  259. </tr>
  260. </tbody>
  261. </table>
  262. <dl class="details">
  263. <dt class="tag-returns"><strong>Returns:</strong> <ul>
  264. <li>Whether the given OBB intersects this OBB or not.</li>
  265. </ul></dt>
  266. </dl>
  267. </div>
  268. <h3 class="name name-method" id="intersectsPlane" translate="no">.<a href="#intersectsPlane">intersectsPlane</a><span class="signature">( plane : <span class="param-type">Plane</span> )</span><span class="type-signature"> : boolean</span> </h3>
  269. <div class="method">
  270. <div class="description">
  271. <p>Returns <code>true</code> if the given plane intersects this OBB.</p>
  272. </div>
  273. <table class="params">
  274. <tbody>
  275. <tr>
  276. <td class="name"><code>plane</code></td>
  277. <td class="description last"><p>The plane to test.</p></td>
  278. </tr>
  279. </tbody>
  280. </table>
  281. <dl class="details">
  282. <dt class="tag-returns"><strong>Returns:</strong> Whether the given plane intersects this OBB or not.</dt>
  283. </dl>
  284. </div>
  285. <h3 class="name name-method" id="intersectsRay" translate="no">.<a href="#intersectsRay">intersectsRay</a><span class="signature">( ray : <span class="param-type">Ray</span> )</span><span class="type-signature"> : boolean</span> </h3>
  286. <div class="method">
  287. <div class="description">
  288. <p>Returns <code>true</code> if the given ray intersects this OBB.</p>
  289. </div>
  290. <table class="params">
  291. <tbody>
  292. <tr>
  293. <td class="name"><code>ray</code></td>
  294. <td class="description last"><p>The ray to test.</p></td>
  295. </tr>
  296. </tbody>
  297. </table>
  298. <dl class="details">
  299. <dt class="tag-returns"><strong>Returns:</strong> Whether the given ray intersects this OBB or not.</dt>
  300. </dl>
  301. </div>
  302. <h3 class="name name-method" id="intersectsSphere" translate="no">.<a href="#intersectsSphere">intersectsSphere</a><span class="signature">( sphere : <span class="param-type">Sphere</span> )</span><span class="type-signature"> : boolean</span> </h3>
  303. <div class="method">
  304. <div class="description">
  305. <p>Returns <code>true</code> if the given bounding sphere intersects this OBB.</p>
  306. </div>
  307. <table class="params">
  308. <tbody>
  309. <tr>
  310. <td class="name"><code>sphere</code></td>
  311. <td class="description last"><p>The bounding sphere to test.</p></td>
  312. </tr>
  313. </tbody>
  314. </table>
  315. <dl class="details">
  316. <dt class="tag-returns"><strong>Returns:</strong> <ul>
  317. <li>Whether the given bounding sphere intersects this OBB or not.</li>
  318. </ul></dt>
  319. </dl>
  320. </div>
  321. <h3 class="name name-method" id="set" translate="no">.<a href="#set">set</a><span class="signature">( center : <span class="param-type">Vector3</span>, halfSize : <span class="param-type">Vector3</span>, rotation : <span class="param-type">Matrix3</span> )</span><span class="type-signature"> : <a href="OBB.html">OBB</a></span> </h3>
  322. <div class="method">
  323. <div class="description">
  324. <p>Sets the OBBs components to the given values.</p>
  325. </div>
  326. <table class="params">
  327. <tbody>
  328. <tr>
  329. <td class="name"><code>center</code></td>
  330. <td class="description last"><p>The center of the OBB.</p></td>
  331. </tr>
  332. <tr>
  333. <td class="name"><code>halfSize</code></td>
  334. <td class="description last"><p>Positive halfwidth extents of the OBB along each axis.</p></td>
  335. </tr>
  336. <tr>
  337. <td class="name"><code>rotation</code></td>
  338. <td class="description last"><p>The rotation of the OBB.</p></td>
  339. </tr>
  340. </tbody>
  341. </table>
  342. <dl class="details">
  343. <dt class="tag-returns"><strong>Returns:</strong> A reference to this OBB.</dt>
  344. </dl>
  345. </div>
  346. <h2 class="subsection-title">Source</h2>
  347. <p>
  348. <a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/math/OBB.js" target="_blank" rel="noopener" translate="no">examples/jsm/math/OBB.js</a>
  349. </p>
  350. </article>
  351. </section>
  352. <script src="../scripts/linenumber.js"></script>
  353. <script src="../scripts/page.js"></script>
  354. </body>
  355. </html>
粤ICP备19079148号