Box3.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="page.css" />
  8. </head>
  9. <body>
  10. <h1>[name]</h1>
  11. <p class="desc">
  12. Represents an axis-aligned bounding box (AABB) in 3D space.
  13. </p>
  14. <h2>Code Example</h2>
  15. <code>
  16. const box = new THREE.Box3();
  17. const mesh = new THREE.Mesh(
  18. new THREE.SphereGeometry(),
  19. new THREE.MeshBasicMaterial()
  20. );
  21. // ensure the bounding box is computed for its geometry
  22. // this should be done only once (assuming static geometries)
  23. mesh.geometry.computeBoundingBox();
  24. // ...
  25. // in the animation loop, compute the current bounding box with the world matrix
  26. box.copy( mesh.geometry.boundingBox ).applyMatrix4( mesh.matrixWorld );
  27. </code>
  28. <h2>Constructor</h2>
  29. <h3>[name]( [param:Vector3 min], [param:Vector3 max] )</h3>
  30. <p>
  31. [page:Vector3 min] - (optional) [page:Vector3] representing the lower (x,
  32. y, z) boundary of the box. Default is ( + Infinity, + Infinity, + Infinity
  33. ).<br />
  34. [page:Vector3 max] - (optional) [page:Vector3] representing the upper (x,
  35. y, z) boundary of the box. Default is ( - Infinity, - Infinity, - Infinity
  36. ).<br /><br />
  37. Creates a [name] bounded by min and max.
  38. </p>
  39. <h2>Properties</h2>
  40. <h3>[property:Boolean isBox3]</h3>
  41. <p>Read-only flag to check if a given object is of type [name].</p>
  42. <h3>[property:Vector3 min]</h3>
  43. <p>
  44. [page:Vector3] representing the lower (x, y, z) boundary of the box.<br />
  45. Default is ( + Infinity, + Infinity, + Infinity ).
  46. </p>
  47. <h3>[property:Vector3 max]</h3>
  48. <p>
  49. [page:Vector3] representing the upper (x, y, z) boundary of the box.<br />
  50. Default is ( - Infinity, - Infinity, - Infinity ).
  51. </p>
  52. <h2>Methods</h2>
  53. <h3>[method:this applyMatrix4]( [param:Matrix4 matrix] )</h3>
  54. <p>
  55. [page:Matrix4 matrix] - The [page:Matrix4] to apply<br /><br />
  56. Transforms this Box3 with the supplied matrix.
  57. </p>
  58. <h3>
  59. [method:Vector3 clampPoint]( [param:Vector3 point], [param:Vector3 target] )
  60. </h3>
  61. <p>
  62. [page:Vector3 point] - [page:Vector3] to clamp. <br />
  63. [page:Vector3 target] — the result will be copied into this Vector3.<br /><br />
  64. [link:https://en.wikipedia.org/wiki/Clamping_(graphics) Clamps] the
  65. [page:Vector3 point] within the bounds of this box.<br />
  66. </p>
  67. <h3>[method:Box3 clone]()</h3>
  68. <p>
  69. Returns a new [page:Box3] with the same [page:.min min] and [page:.max max] as this one.
  70. </p>
  71. <h3>[method:Boolean containsBox]( [param:Box3 box] )</h3>
  72. <p>
  73. [page:Box3 box] - [page:Box3 Box3] to test for inclusion.<br /><br />
  74. Returns true if this box includes the entirety of [page:Box3 box]. If this
  75. and [page:Box3 box] are identical, <br />
  76. this function also returns true.
  77. </p>
  78. <h3>[method:Boolean containsPoint]( [param:Vector3 point] )</h3>
  79. <p>
  80. [page:Vector3 point] - [page:Vector3] to check for inclusion.<br /><br />
  81. Returns true if the specified [page:Vector3 point] lies within or on the
  82. boundaries of this box.
  83. </p>
  84. <h3>[method:this copy]( [param:Box3 box] )</h3>
  85. <p>
  86. [page:Box3 box] - [page:Box3] to copy.<br /><br />
  87. Copies the [page:.min min] and [page:.max max] from [page:Box3 box] to
  88. this box.
  89. </p>
  90. <h3>[method:Float distanceToPoint]( [param:Vector3 point] )</h3>
  91. <p>
  92. [page:Vector3 point] - [page:Vector3] to measure distance to.<br /><br />
  93. Returns the distance from any edge of this box to the specified point. If
  94. the [page:Vector3 point] lies inside of this box, the distance will be `0`.
  95. </p>
  96. <h3>[method:Boolean equals]( [param:Box3 box] )</h3>
  97. <p>
  98. [page:Box3 box] - Box to compare with this one.<br /><br />
  99. Returns true if this box and [page:Box3 box] share the same lower and
  100. upper bounds.
  101. </p>
  102. <h3>
  103. [method:this expandByObject]( [param:Object3D object], [param:Boolean precise] )
  104. </h3>
  105. <p>
  106. [page:Object3D object] - [page:Object3D] to expand the box by.<br />
  107. precise - (optional) expand the bounding box as little as necessary at the
  108. expense of more computation. Default is false.<br /><br />
  109. Expands the boundaries of this box to include [page:Object3D object] and
  110. its children, accounting for the object's, and children's, world
  111. transforms. The function may result in a larger box than strictly
  112. necessary (unless the precise parameter is set to true).
  113. </p>
  114. <h3>[method:this expandByPoint]( [param:Vector3 point] )</h3>
  115. <p>
  116. [page:Vector3 point] - [page:Vector3] that should be included in the
  117. box.<br /><br />
  118. Expands the boundaries of this box to include [page:Vector3 point].
  119. </p>
  120. <h3>[method:this expandByScalar]( [param:Float scalar] )</h3>
  121. <p>
  122. [page:Float scalar] - Distance to expand the box by.<br /><br />
  123. Expands each dimension of the box by [page:Float scalar]. If negative, the
  124. dimensions of the box will be contracted.
  125. </p>
  126. <h3>[method:this expandByVector]( [param:Vector3 vector] )</h3>
  127. <p>
  128. [page:Vector3 vector] - [page:Vector3] to expand the box by.<br /><br />
  129. Expands this box equilaterally by [page:Vector3 vector]. The width of this
  130. box will be expanded by the x component of [page:Vector3 vector] in both
  131. directions. The height of this box will be expanded by the y component of
  132. [page:Vector3 vector] in both directions. The depth of this box will be
  133. expanded by the z component of `vector` in both directions.
  134. </p>
  135. <h3>[method:Sphere getBoundingSphere]( [param:Sphere target] )</h3>
  136. <p>
  137. [page:Sphere target] — the result will be copied into this Sphere.<br /><br />
  138. Gets a [page:Sphere] that bounds the box.
  139. </p>
  140. <h3>[method:Vector3 getCenter]( [param:Vector3 target] )</h3>
  141. <p>
  142. [page:Vector3 target] — the result will be copied into this Vector3.<br /><br />
  143. Returns the center point of the box as a [page:Vector3].
  144. </p>
  145. <h3>
  146. [method:Vector3 getParameter]( [param:Vector3 point], [param:Vector3 target] )
  147. </h3>
  148. <p>
  149. [page:Vector3 point] - [page:Vector3].<br />
  150. [page:Vector3 target] — the result will be copied into this Vector3.<br /><br />
  151. Returns a point as a proportion of this box's width, height and depth.
  152. </p>
  153. <h3>[method:Vector3 getSize]( [param:Vector3 target] )</h3>
  154. <p>
  155. [page:Vector3 target] — the result will be copied into this Vector3.<br /><br />
  156. Returns the width, height and depth of this box.
  157. </p>
  158. <h3>[method:this intersect]( [param:Box3 box] )</h3>
  159. <p>
  160. [page:Box3 box] - Box to intersect with.<br /><br />
  161. Computes the intersection of this and [page:Box3 box], setting the upper
  162. bound of this box to the lesser of the two boxes' upper bounds and the
  163. lower bound of this box to the greater of the two boxes' lower bounds. If
  164. there's no overlap, makes this box empty.
  165. </p>
  166. <h3>[method:Boolean intersectsBox]( [param:Box3 box] )</h3>
  167. <p>
  168. [page:Box3 box] - Box to check for intersection against.<br /><br />
  169. Determines whether or not this box intersects [page:Box3 box].
  170. </p>
  171. <h3>[method:Boolean intersectsPlane]( [param:Plane plane] )</h3>
  172. <p>
  173. [page:Plane plane] - [page:Plane] to check for intersection against.<br /><br />
  174. Determines whether or not this box intersects [page:Plane plane].
  175. </p>
  176. <h3>[method:Boolean intersectsSphere]( [param:Sphere sphere] )</h3>
  177. <p>
  178. [page:Sphere sphere] - [page:Sphere] to check for intersection against.<br /><br />
  179. Determines whether or not this box intersects [page:Sphere sphere].
  180. </p>
  181. <h3>[method:Boolean intersectsTriangle]( [param:Triangle triangle] )</h3>
  182. <p>
  183. [page:Triangle triangle] - [page:Triangle] to check for intersection
  184. against.<br /><br />
  185. Determines whether or not this box intersects [page:Triangle triangle].
  186. </p>
  187. <h3>[method:Boolean isEmpty]()</h3>
  188. <p>
  189. Returns true if this box includes zero points within its bounds.<br />
  190. Note that a box with equal lower and upper bounds still includes one
  191. point, the one both bounds share.
  192. </p>
  193. <h3>[method:this makeEmpty]()</h3>
  194. <p>Makes this box empty.</p>
  195. <h3>[method:this set]( [param:Vector3 min], [param:Vector3 max] )</h3>
  196. <p>
  197. [page:Vector3 min] - [page:Vector3] representing the lower (x, y, z)
  198. boundary of the box.<br />
  199. [page:Vector3 max] - [page:Vector3] representing the upper (x, y, z)
  200. boundary of the box.<br /><br />
  201. Sets the lower and upper (x, y, z) boundaries of this box.<br />
  202. Please note that this method only copies the values from the given
  203. objects.
  204. </p>
  205. <h3>[method:this setFromArray]( [param:Array array] )</h3>
  206. <p>
  207. array -- An array of position data that the resulting box will envelop.<br /><br />
  208. Sets the upper and lower bounds of this box to include all of the data in
  209. `array`.
  210. </p>
  211. <h3>
  212. [method:this setFromBufferAttribute]( [param:BufferAttribute attribute] )
  213. </h3>
  214. <p>
  215. [page:BufferAttribute attribute] - A buffer attribute of position data
  216. that the resulting box will envelop.<br /><br />
  217. Sets the upper and lower bounds of this box to include all of the data in
  218. [page:BufferAttribute attribute].
  219. </p>
  220. <h3>
  221. [method:this setFromCenterAndSize]( [param:Vector3 center], [param:Vector3 size] )
  222. </h3>
  223. <p>
  224. [page:Vector3 center], - Desired center position of the box. <br />
  225. [page:Vector3 size] - Desired x, y and z dimensions of the box.<br /><br />
  226. Centers this box on [page:Vector3 center] and sets this box's width,
  227. height and depth to the values specified <br />
  228. in [page:Vector3 size]
  229. </p>
  230. <h3>
  231. [method:this setFromObject]( [param:Object3D object], [param:Boolean precise] )
  232. </h3>
  233. <p>
  234. [page:Object3D object] - [page:Object3D] to compute the bounding box
  235. of.<br />
  236. precise - (optional) compute the smallest world-axis-aligned bounding box
  237. at the expense of more computation. Default is false.<br /><br />
  238. Computes the world-axis-aligned bounding box of an [page:Object3D]
  239. (including its children), accounting for the object's, and children's,
  240. world transforms. The function may result in a larger box than strictly
  241. necessary.
  242. </p>
  243. <h3>[method:this setFromPoints]( [param:Array points] )</h3>
  244. <p>
  245. [page:Array points] - Array of [page:Vector3 Vector3s] that the resulting
  246. box will contain.<br /><br />
  247. Sets the upper and lower bounds of this box to include all of the points
  248. in [page:Array points].
  249. </p>
  250. <h3>[method:this translate]( [param:Vector3 offset] )</h3>
  251. <p>
  252. [page:Vector3 offset] - Direction and distance of offset.<br /><br />
  253. Adds [page:Vector3 offset] to both the upper and lower bounds of this box,
  254. effectively moving this box [page:Vector3 offset] units in 3D space.
  255. </p>
  256. <h3>[method:this union]( [param:Box3 box] )</h3>
  257. <p>
  258. [page:Box3 box] - Box that will be unioned with this box.<br /><br />
  259. Computes the union of this box and [page:Box3 box], setting the upper
  260. bound of this box to the greater of the two boxes' upper bounds and the
  261. lower bound of this box to the lesser of the two boxes' lower bounds.
  262. </p>
  263. <h2>Source</h2>
  264. <p>
  265. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  266. </p>
  267. </body>
  268. </html>