Box3.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <!DOCTYPE html>
  2. <html lang="zh">
  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. 表示三维空间中的一个轴对齐包围盒(axis-aligned bounding box,AABB)。
  13. </p>
  14. <h2>代码示例</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] - (参数可选) [page:Vector3] 表示包围盒的下边界。
  32. 默认值是( + Infinity, + Infinity, + Infinity )。<br>
  33. [page:Vector3 max] - (参数可选) [page:Vector3] 表示包围盒的上边界。
  34. 默认值是( - Infinity, - Infinity, - Infinity )。<br /><br />
  35. 创建一个以max和min为边界的包围盒。
  36. </p>
  37. <h2>属性(Properties)</h2>
  38. <h3>[property:Boolean isBox3]</h3>
  39. <p>
  40. Read-only flag to check if a given object is of type [name].
  41. </p>
  42. <h3>[property:Vector3 min]</h3>
  43. <p>
  44. [page:Vector3] 表示包围盒的下边界。<br />
  45. 默认值是( + Infinity, + Infinity, + Infinity )。
  46. </p>
  47. <h3>[property:Vector3 max]</h3>
  48. <p>
  49. [page:Vector3] 包围盒的(x, y, z)上边界。<br />
  50. 默认值是 ( - Infinity, - Infinity, - Infinity ).
  51. </p>
  52. <h2>方法(Methods)</h2>
  53. <h3>[method:this applyMatrix4]( [param:Matrix4 matrix] )</h3>
  54. <p>
  55. [page:Matrix4 matrix] - 要应用的 [page:Matrix4] <br /><br />
  56. 使用传入的矩阵变换Box3(包围盒8个顶点都会乘以这个变换矩阵)。
  57. </p>
  58. <h3>[method:Vector3 clampPoint]( [param:Vector3 point], [param:Vector3 target] )</h3>
  59. <p>
  60. [page:Vector3 point] - 需要做clamp 的坐标 [page:Vector3]。 <br>
  61. [page:Vector3 target] — 结果将会被拷贝到这个对象中<br /><br />
  62. 使这个点[page:Vector3 point] [link:https://en.wikipedia.org/wiki/Clamping_(graphics) Clamps](处于范围内) 处于包围盒边界范围内。<br />
  63. </p>
  64. <h3>[method:Box3 clone]()</h3>
  65. <p>返回一个与该包围盒子有相同下边界[page:.min min] 和上边界 [page:.max max]的新包围盒。</p>
  66. <h3>[method:Boolean containsBox]( [param:Box3 box] )</h3>
  67. <p>
  68. [page:Box3 box] - 需要检测是否在当前包围盒内的 [page:Box3 Box3]。<br /><br />
  69. 传入的 [page:Box3 box] 整体都被包含在该对象中则返回true。如果他们两个包围盒是一样的也返回true。
  70. </p>
  71. <h3>[method:Boolean containsPoint]( [param:Vector3 point] )</h3>
  72. <p>
  73. [page:Vector3 point] - 需要检测是否在当前包围盒内的 [page:Vector3]。<br /><br />
  74. 当传入的值 [page:Vector3 point] 在包围盒内部或者边界都会返回true。
  75. </p>
  76. <h3>[method:this copy]( [param:Box3 box] )</h3>
  77. <p>
  78. [page:Box3 box] - 需要复制的包围盒 [page:Box3] 。<br /><br />
  79. 将传入的值 [page:Box3 box] 中的 [page:.min min] 和 [page:.max max] 拷贝到当前对象。
  80. </p>
  81. <h3>[method:Float distanceToPoint]( [param:Vector3 point] )</h3>
  82. <p>
  83. [page:Vector3 point] - 用来测试距离的点 [page:Vector3]。<br /><br />
  84. 返回这个box的任何边缘到指定点的距离。如果这个点位于这个盒子里,距离将是0。
  85. </p>
  86. <h3>[method:Boolean equals]( [param:Box3 box] )</h3>
  87. <p>
  88. [page:Box3 box] - 将box与当前对象做比较。<br /><br />
  89. 返回true如果传入的值与当前的对象 [page:Box3 box] 有相同的上下边界。
  90. </p>
  91. <h3>[method:this expandByObject]( [param:Object3D object] )</h3>
  92. <p>
  93. [page:Object3D object] - 包裹在包围盒中的3d对象 [page:Object3D]。<br /><br />
  94. 扩展此包围盒的边界,使得对象及其子对象在包围盒内,包括对象和子对象的世界坐标的变换。
  95. 该方法可能会导致一个比严格需要的更大的框。
  96. </p>
  97. <h3>[method:this expandByPoint]( [param:Vector3 point] )</h3>
  98. <p>
  99. [page:Vector3 point] - 需要在包围盒中的点 [page:Vector3]。<br /><br />
  100. 扩展这个包围盒的边界使得该点([page:Vector3 point])在包围盒内。
  101. </p>
  102. <h3>[method:this expandByScalar]( [param:Float scalar] )</h3>
  103. <p>
  104. [page:Float scalar] - 扩展包围盒的比例。<br /><br />
  105. 按 [page:Float scalar] 的值展开盒子的每个维度。如果是负数,盒子的尺寸会缩小。
  106. </p>
  107. <h3>[method:this expandByVector]( [param:Vector3 vector] )</h3>
  108. <p>
  109. [page:Vector3 vector] - 扩展包围盒的数值 [page:Vector3] 。<br /><br />
  110. 按 [page:Vector3 vector] 每个纬度的值展开这个箱子。
  111. 这个盒子的宽度将由 [page:Vector3 vector] 的x分量在两个方向上展开。
  112. 这个盒子的高度将由 [page:Vector3 vector] 两个方向上的y分量展开。
  113. 这个盒子的深度将由 [page:Vector3 vector] z分量在两个方向上展开。
  114. </p>
  115. <h3>[method:Sphere getBoundingSphere]( [param:Sphere target] )</h3>
  116. <p>
  117. [page:Sphere target] — 如果指定了target ,结果将会被拷贝到target。<br /><br />
  118. 获取一个包围球 [page:Sphere]。
  119. </p>
  120. <h3>[method:Vector3 getCenter]( [param:Vector3 target] )</h3>
  121. <p>
  122. [page:Vector3 target] — 如果指定了target ,结果将会被拷贝到target。<br /><br />
  123. 返回包围盒的中心点 [page:Vector3]。
  124. </p>
  125. <h3>[method:Vector3 getParameter]( [param:Vector3 point], [param:Vector3 target] ) </h3>
  126. <p>
  127. [page:Vector3 point] - [page:Vector3].<br/>
  128. [page:Vector3 target] — 如果指定了target ,结果将会被拷贝到target。<br /><br />
  129. 返回一个点为这个盒子的宽度、高度和深度的比例。
  130. </p>
  131. <h3>[method:Vector3 getSize]( [param:Vector3 target] )</h3>
  132. <p>
  133. [page:Vector3 target] — 如果指定了target ,结果将会被拷贝到target。<br /><br />
  134. 返回包围盒的宽度,高度,和深度。
  135. </p>
  136. <h3>[method:this intersect]( [param:Box3 box] )</h3>
  137. <p>
  138. [page:Box3 box] - 与包围盒的交集<br /><br />
  139. 计算此包围盒和 [page:Box3 box] 的交集,将此框的上界设置为两个框的max的较小部分,
  140. 将此包围盒的下界设置为两个包围盒的min的较大部分。如果两个包围盒不相交,则清空此包围盒。
  141. </p>
  142. <h3>[method:Boolean intersectsBox]( [param:Box3 box] )</h3>
  143. <p>
  144. [page:Box3 box] - 用来检测是否相交的包围盒<br /><br />
  145. 确定当前包围盒是否与传入包围盒[page:Box3 box] 相交。
  146. </p>
  147. <h3>[method:Boolean intersectsPlane]( [param:Plane plane] )</h3>
  148. <p>
  149. [page:Plane plane] - 用来检测是否相交的 [page:Plane]。<br /><br />
  150. 确定当前包围盒是否与平面 [page:Plane plane] 相交。
  151. </p>
  152. <h3>[method:Boolean intersectsSphere]( [param:Sphere sphere] )</h3>
  153. <p>
  154. [page:Sphere sphere] - 用来检测是否相交的球体 [page:Sphere]。<br /><br />
  155. 确定当前包围盒是否与球体 [page:Sphere sphere] 相交。
  156. </p>
  157. <h3>[method:Boolean intersectsTriangle]( [param:Triangle triangle] )</h3>
  158. <p>
  159. [page:Triangle triangle] - 用来检测是否相交的三角形 [page:Triangle]。<br /><br />
  160. 确定当前包围盒是否与三角形 [page:Triangle triangle] 相交。
  161. </p>
  162. <h3>[method:Boolean isEmpty]()</h3>
  163. <p>
  164. 如果这个盒子包含0个顶点,则返回true。<br>
  165. 注意,下界和上界相等的方框仍然包含一个点,即两个边界共享的那个点。
  166. </p>
  167. <h3>[method:this makeEmpty]()</h3>
  168. <p>清空包围盒。</p>
  169. <h3>[method:this set]( [param:Vector3 min], [param:Vector3 max] )</h3>
  170. <p>
  171. [page:Vector3 min] - [page:Vector3] 表示下边界每个纬度(x,y,z)的值。<br />
  172. [page:Vector3 max] - [page:Vector3] 表示上边界每个纬度(x,y,z)的值。<br /><br />
  173. 设置包围盒上下边界每个纬度(x,y,z)的值。<br>
  174. 请注意,此方法仅复制给定对象的值。
  175. </p>
  176. <h3>[method:this setFromArray]( [param:Array array] )</h3>
  177. <p>
  178. array - 数组当中的所有的点都将被包围盒包裹。<br /><br />
  179. 设置包围盒的上下边界使得数组 *array* 中的所有点的点都被包含在内。
  180. </p>
  181. <h3>[method:this setFromBufferAttribute]( [param:BufferAttribute attribute] )</h3>
  182. <p>
  183. [page:BufferAttribute attribute] - 位置的缓冲数据,包含在返回的包围盒内。<br /><br />
  184. 设置此包围盒的上边界和下边界,以包含 [page:BufferAttribute attribute] 中的所有位置数据。
  185. </p>
  186. <h3>[method:this setFromCenterAndSize]( [param:Vector3 center], [param:Vector3 size] )</h3>
  187. <p>
  188. [page:Vector3 center], - 包围盒所要设置的中心位置。 <br>
  189. [page:Vector3 size] - 包围盒所要设置的x、y和z尺寸(宽/高/长)。<br /><br />
  190. 将当前包围盒的中心点设置为 [page:Vector3 center] ,并将此包围盒的宽度,高度和深度设置为大小指定 [page:Vector3 size] 的值。
  191. </p>
  192. <h3>[method:this setFromObject]( [param:Object3D object] )</h3>
  193. <p>
  194. [page:Object3D object] - 用来计算包围盒的3D对象 [page:Object3D]。<br /><br />
  195. 计算和世界轴对齐的一个对象 [page:Object3D] (含其子对象)的包围盒,计算对象和子对象的世界坐标变换。
  196. 该方法可能会导致一个比严格需要的更大的框。
  197. </p>
  198. <h3>[method:this setFromPoints]( [param:Array points] )</h3>
  199. <p>
  200. [page:Array points] - 计算出的包围盒将包含数组中所有的点 [page:Vector3 Vector3s]<br /><br />
  201. 设置此包围盒的上边界和下边界,以包含数组 [page:Array points] 中的所有点。
  202. </p>
  203. <h3>[method:this translate]( [param:Vector3 offset] )</h3>
  204. <p>
  205. [page:Vector3 offset] - 偏移方向和距离。<br /><br />
  206. 给包围盒的上下边界添加偏移量 [page:Vector3 offset],这样可以有效的在3D空间中移动包围盒。
  207. 偏移量为 [page:Vector3 offset] 大小。
  208. </p>
  209. <h3>[method:this union]( [param:Box3 box] )</h3>
  210. <p>
  211. [page:Box3 box] - 将被用于与该盒子计算并集的盒子。<br /><br />
  212. 在 [page:Box3 box] 参数的上边界和已有box对象的上边界之间取较大者,而对两者的下边界取较小者,这样获得一个新的较大的联合盒子。
  213. </p>
  214. <h2>源码(Source)</h2>
  215. <p>
  216. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  217. </p>
  218. </body>
  219. </html>