OBB.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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" rel="noopener">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"><a href="Vector3.html">Vector3</a></span>, halfSize : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, rotation : <span class="param-type"><a href="Matrix3.html">Matrix3</a></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">
  32. <strong>center</strong>
  33. </td>
  34. <td class="description last">
  35. <p>The center of the OBB.</p>
  36. </td>
  37. </tr>
  38. <tr>
  39. <td class="name">
  40. <strong>halfSize</strong>
  41. </td>
  42. <td class="description last">
  43. <p>Positive halfwidth extents of the OBB along each axis.</p>
  44. </td>
  45. </tr>
  46. <tr>
  47. <td class="name">
  48. <strong>rotation</strong>
  49. </td>
  50. <td class="description last">
  51. <p>The rotation of the OBB.</p>
  52. </td>
  53. </tr>
  54. </tbody>
  55. </table>
  56. </div>
  57. </div>
  58. <h2 class="subsection-title">Properties</h2>
  59. <div class="member">
  60. <h3 class="name" id="center" translate="no">.<a href="#center">center</a><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
  61. <div class="description">
  62. <p>The center of the OBB.</p>
  63. </div>
  64. </div>
  65. <div class="member">
  66. <h3 class="name" id="halfSize" translate="no">.<a href="#halfSize">halfSize</a><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
  67. <div class="description">
  68. <p>Positive halfwidth extents of the OBB along each axis.</p>
  69. </div>
  70. </div>
  71. <div class="member">
  72. <h3 class="name" id="rotation" translate="no">.<a href="#rotation">rotation</a><span class="type-signature"> : <a href="Matrix3.html">Matrix3</a></span> </h3>
  73. <div class="description">
  74. <p>The rotation of the OBB.</p>
  75. </div>
  76. </div>
  77. <h2 class="subsection-title">Methods</h2>
  78. <h3 class="name name-method" id="applyMatrix4" translate="no">.<a href="#applyMatrix4">applyMatrix4</a><span class="signature">( matrix : <span class="param-type"><a href="Matrix4.html">Matrix4</a></span> )</span><span class="type-signature"> : <a href="OBB.html">OBB</a></span> </h3>
  79. <div class="method">
  80. <div class="description">
  81. <p>Applies the given transformation matrix to this OBB. This method can be
  82. used to transform the bounding volume with the world matrix of a 3D object
  83. in order to keep both entities in sync.</p>
  84. </div>
  85. <table class="params">
  86. <tbody>
  87. <tr>
  88. <td class="name">
  89. <strong>matrix</strong>
  90. </td>
  91. <td class="description last">
  92. <p>The matrix to apply.</p>
  93. </td>
  94. </tr>
  95. </tbody>
  96. </table>
  97. <dl class="details">
  98. <dt class="tag-returns"><strong>Returns:</strong> A reference of this OBB.</dt>
  99. </dl>
  100. </div>
  101. <h3 class="name name-method" id="clampPoint" translate="no">.<a href="#clampPoint">clampPoint</a><span class="signature">( point : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, target : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
  102. <div class="method">
  103. <div class="description">
  104. <p>Clamps the given point within the bounds of this OBB.</p>
  105. </div>
  106. <table class="params">
  107. <tbody>
  108. <tr>
  109. <td class="name">
  110. <strong>point</strong>
  111. </td>
  112. <td class="description last">
  113. <p>The point that should be clamped within the bounds of this OBB.</p>
  114. </td>
  115. </tr>
  116. <tr>
  117. <td class="name">
  118. <strong>target</strong>
  119. </td>
  120. <td class="description last">
  121. <p>The target vector that is used to store the method's result.</p>
  122. </td>
  123. </tr>
  124. </tbody>
  125. </table>
  126. <dl class="details">
  127. <dt class="tag-returns"><strong>Returns:</strong> <ul>
  128. <li>The clamped point.</li>
  129. </ul></dt>
  130. </dl>
  131. </div>
  132. <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>
  133. <div class="method">
  134. <div class="description">
  135. <p>Returns a new OBB with copied values from this instance.</p>
  136. </div>
  137. <dl class="details">
  138. <dt class="tag-returns"><strong>Returns:</strong> A clone of this instance.</dt>
  139. </dl>
  140. </div>
  141. <h3 class="name name-method" id="containsPoint" translate="no">.<a href="#containsPoint">containsPoint</a><span class="signature">( point : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : boolean</span> </h3>
  142. <div class="method">
  143. <div class="description">
  144. <p>Returns <code>true</code> if the given point lies within this OBB.</p>
  145. </div>
  146. <table class="params">
  147. <tbody>
  148. <tr>
  149. <td class="name">
  150. <strong>point</strong>
  151. </td>
  152. <td class="description last">
  153. <p>The point to test.</p>
  154. </td>
  155. </tr>
  156. </tbody>
  157. </table>
  158. <dl class="details">
  159. <dt class="tag-returns"><strong>Returns:</strong> <ul>
  160. <li>Whether the given point lies within this OBB or not.</li>
  161. </ul></dt>
  162. </dl>
  163. </div>
  164. <h3 class="name name-method" id="copy" translate="no">.<a href="#copy">copy</a><span class="signature">( obb : <span class="param-type"><a href="OBB.html">OBB</a></span> )</span><span class="type-signature"> : <a href="OBB.html">OBB</a></span> </h3>
  165. <div class="method">
  166. <div class="description">
  167. <p>Copies the values of the given OBB to this instance.</p>
  168. </div>
  169. <table class="params">
  170. <tbody>
  171. <tr>
  172. <td class="name">
  173. <strong>obb</strong>
  174. </td>
  175. <td class="description last">
  176. <p>The OBB to copy.</p>
  177. </td>
  178. </tr>
  179. </tbody>
  180. </table>
  181. <dl class="details">
  182. <dt class="tag-returns"><strong>Returns:</strong> A reference to this OBB.</dt>
  183. </dl>
  184. </div>
  185. <h3 class="name name-method" id="equals" translate="no">.<a href="#equals">equals</a><span class="signature">( obb : <span class="param-type"><a href="OBB.html">OBB</a></span> )</span><span class="type-signature"> : boolean</span> </h3>
  186. <div class="method">
  187. <div class="description">
  188. <p>Returns <code>true</code> if the given OBB is equal to this OBB.</p>
  189. </div>
  190. <table class="params">
  191. <tbody>
  192. <tr>
  193. <td class="name">
  194. <strong>obb</strong>
  195. </td>
  196. <td class="description last">
  197. <p>The OBB to test.</p>
  198. </td>
  199. </tr>
  200. </tbody>
  201. </table>
  202. <dl class="details">
  203. <dt class="tag-returns"><strong>Returns:</strong> Whether the given OBB is equal to this OBB or not.</dt>
  204. </dl>
  205. </div>
  206. <h3 class="name name-method" id="fromBox3" translate="no">.<a href="#fromBox3">fromBox3</a><span class="signature">( box3 : <span class="param-type"><a href="Box3.html">Box3</a></span> )</span><span class="type-signature"> : <a href="OBB.html">OBB</a></span> </h3>
  207. <div class="method">
  208. <div class="description">
  209. <p>Defines an OBB based on the given AABB.</p>
  210. </div>
  211. <table class="params">
  212. <tbody>
  213. <tr>
  214. <td class="name">
  215. <strong>box3</strong>
  216. </td>
  217. <td class="description last">
  218. <p>The AABB to setup the OBB from.</p>
  219. </td>
  220. </tr>
  221. </tbody>
  222. </table>
  223. <dl class="details">
  224. <dt class="tag-returns"><strong>Returns:</strong> A reference of this OBB.</dt>
  225. </dl>
  226. </div>
  227. <h3 class="name name-method" id="getSize" translate="no">.<a href="#getSize">getSize</a><span class="signature">( target : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
  228. <div class="method">
  229. <div class="description">
  230. <p>Returns the size of this OBB.</p>
  231. </div>
  232. <table class="params">
  233. <tbody>
  234. <tr>
  235. <td class="name">
  236. <strong>target</strong>
  237. </td>
  238. <td class="description last">
  239. <p>The target vector that is used to store the method's result.</p>
  240. </td>
  241. </tr>
  242. </tbody>
  243. </table>
  244. <dl class="details">
  245. <dt class="tag-returns"><strong>Returns:</strong> The size.</dt>
  246. </dl>
  247. </div>
  248. <h3 class="name name-method" id="intersectRay" translate="no">.<a href="#intersectRay">intersectRay</a><span class="signature">( ray : <span class="param-type"><a href="Ray.html">Ray</a></span>, target : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
  249. <div class="method">
  250. <div class="description">
  251. <p>Performs a ray/OBB intersection test and stores the intersection point
  252. in the given 3D vector.</p>
  253. </div>
  254. <table class="params">
  255. <tbody>
  256. <tr>
  257. <td class="name">
  258. <strong>ray</strong>
  259. </td>
  260. <td class="description last">
  261. <p>The ray to test.</p>
  262. </td>
  263. </tr>
  264. <tr>
  265. <td class="name">
  266. <strong>target</strong>
  267. </td>
  268. <td class="description last">
  269. <p>The target vector that is used to store the method's result.</p>
  270. </td>
  271. </tr>
  272. </tbody>
  273. </table>
  274. <dl class="details">
  275. <dt class="tag-returns"><strong>Returns:</strong> The intersection point. If no intersection is detected, <code>null</code> is returned.</dt>
  276. </dl>
  277. </div>
  278. <h3 class="name name-method" id="intersectsBox3" translate="no">.<a href="#intersectsBox3">intersectsBox3</a><span class="signature">( box3 : <span class="param-type"><a href="Box3.html">Box3</a></span> )</span><span class="type-signature"> : boolean</span> </h3>
  279. <div class="method">
  280. <div class="description">
  281. <p>Returns <code>true</code> if the given AABB intersects this OBB.</p>
  282. </div>
  283. <table class="params">
  284. <tbody>
  285. <tr>
  286. <td class="name">
  287. <strong>box3</strong>
  288. </td>
  289. <td class="description last">
  290. <p>The AABB to test.</p>
  291. </td>
  292. </tr>
  293. </tbody>
  294. </table>
  295. <dl class="details">
  296. <dt class="tag-returns"><strong>Returns:</strong> <ul>
  297. <li>Whether the given AABB intersects this OBB or not.</li>
  298. </ul></dt>
  299. </dl>
  300. </div>
  301. <h3 class="name name-method" id="intersectsOBB" translate="no">.<a href="#intersectsOBB">intersectsOBB</a><span class="signature">( obb : <span class="param-type"><a href="OBB.html">OBB</a></span>, epsilon : <span class="param-type">number</span> )</span><span class="type-signature"> : boolean</span> </h3>
  302. <div class="method">
  303. <div class="description">
  304. <p>Returns <code>true</code> if the given OBB intersects this OBB.</p>
  305. </div>
  306. <table class="params">
  307. <tbody>
  308. <tr>
  309. <td class="name">
  310. <strong>obb</strong>
  311. </td>
  312. <td class="description last">
  313. <p>The OBB to test.</p>
  314. </td>
  315. </tr>
  316. <tr>
  317. <td class="name">
  318. <strong>epsilon</strong>
  319. </td>
  320. <td class="description last">
  321. <p>A small value to prevent arithmetic errors.</p>
  322. <p>Default is <code>Number.EPSILON</code>.</p>
  323. </td>
  324. </tr>
  325. </tbody>
  326. </table>
  327. <dl class="details">
  328. <dt class="tag-returns"><strong>Returns:</strong> <ul>
  329. <li>Whether the given OBB intersects this OBB or not.</li>
  330. </ul></dt>
  331. </dl>
  332. </div>
  333. <h3 class="name name-method" id="intersectsPlane" translate="no">.<a href="#intersectsPlane">intersectsPlane</a><span class="signature">( plane : <span class="param-type"><a href="Plane.html">Plane</a></span> )</span><span class="type-signature"> : boolean</span> </h3>
  334. <div class="method">
  335. <div class="description">
  336. <p>Returns <code>true</code> if the given plane intersects this OBB.</p>
  337. </div>
  338. <table class="params">
  339. <tbody>
  340. <tr>
  341. <td class="name">
  342. <strong>plane</strong>
  343. </td>
  344. <td class="description last">
  345. <p>The plane to test.</p>
  346. </td>
  347. </tr>
  348. </tbody>
  349. </table>
  350. <dl class="details">
  351. <dt class="tag-returns"><strong>Returns:</strong> Whether the given plane intersects this OBB or not.</dt>
  352. </dl>
  353. </div>
  354. <h3 class="name name-method" id="intersectsRay" translate="no">.<a href="#intersectsRay">intersectsRay</a><span class="signature">( ray : <span class="param-type"><a href="Ray.html">Ray</a></span> )</span><span class="type-signature"> : boolean</span> </h3>
  355. <div class="method">
  356. <div class="description">
  357. <p>Returns <code>true</code> if the given ray intersects this OBB.</p>
  358. </div>
  359. <table class="params">
  360. <tbody>
  361. <tr>
  362. <td class="name">
  363. <strong>ray</strong>
  364. </td>
  365. <td class="description last">
  366. <p>The ray to test.</p>
  367. </td>
  368. </tr>
  369. </tbody>
  370. </table>
  371. <dl class="details">
  372. <dt class="tag-returns"><strong>Returns:</strong> Whether the given ray intersects this OBB or not.</dt>
  373. </dl>
  374. </div>
  375. <h3 class="name name-method" id="intersectsSphere" translate="no">.<a href="#intersectsSphere">intersectsSphere</a><span class="signature">( sphere : <span class="param-type"><a href="Sphere.html">Sphere</a></span> )</span><span class="type-signature"> : boolean</span> </h3>
  376. <div class="method">
  377. <div class="description">
  378. <p>Returns <code>true</code> if the given bounding sphere intersects this OBB.</p>
  379. </div>
  380. <table class="params">
  381. <tbody>
  382. <tr>
  383. <td class="name">
  384. <strong>sphere</strong>
  385. </td>
  386. <td class="description last">
  387. <p>The bounding sphere to test.</p>
  388. </td>
  389. </tr>
  390. </tbody>
  391. </table>
  392. <dl class="details">
  393. <dt class="tag-returns"><strong>Returns:</strong> <ul>
  394. <li>Whether the given bounding sphere intersects this OBB or not.</li>
  395. </ul></dt>
  396. </dl>
  397. </div>
  398. <h3 class="name name-method" id="set" translate="no">.<a href="#set">set</a><span class="signature">( center : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, halfSize : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, rotation : <span class="param-type"><a href="Matrix3.html">Matrix3</a></span> )</span><span class="type-signature"> : <a href="OBB.html">OBB</a></span> </h3>
  399. <div class="method">
  400. <div class="description">
  401. <p>Sets the OBBs components to the given values.</p>
  402. </div>
  403. <table class="params">
  404. <tbody>
  405. <tr>
  406. <td class="name">
  407. <strong>center</strong>
  408. </td>
  409. <td class="description last">
  410. <p>The center of the OBB.</p>
  411. </td>
  412. </tr>
  413. <tr>
  414. <td class="name">
  415. <strong>halfSize</strong>
  416. </td>
  417. <td class="description last">
  418. <p>Positive halfwidth extents of the OBB along each axis.</p>
  419. </td>
  420. </tr>
  421. <tr>
  422. <td class="name">
  423. <strong>rotation</strong>
  424. </td>
  425. <td class="description last">
  426. <p>The rotation of the OBB.</p>
  427. </td>
  428. </tr>
  429. </tbody>
  430. </table>
  431. <dl class="details">
  432. <dt class="tag-returns"><strong>Returns:</strong> A reference to this OBB.</dt>
  433. </dl>
  434. </div>
  435. <h2 class="subsection-title">Source</h2>
  436. <p>
  437. <a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/math/OBB.js" translate="no" target="_blank" rel="noopener">examples/jsm/math/OBB.js</a>
  438. </p>
  439. </article>
  440. </section>
  441. <script src="../scripts/linenumber.js"></script>
  442. <script src="../scripts/page.js"></script>
  443. </body>
  444. </html>
粤ICP备19079148号