BoxHelper.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="list.js"></script>
  7. <script src="page.js"></script>
  8. <link type="text/css" rel="stylesheet" href="page.css" />
  9. </head>
  10. <body>
  11. [page:LineSegments] &rarr;
  12. <h1>[name]</h1>
  13. <p class="desc">
  14. Helper object to graphically show the world-axis-aligned bounding box around an object. The actual bounding box is handled with [page:Box3], this is just a visual helper for debugging.
  15. It can be automatically resized with the [page:BoxHelper.update] method when the object it's created from is transformed.
  16. Note that the object must have a [page:Geometry] or [page:BufferGeometry] for this to work,
  17. so it won't work with [page:Sprite Sprites].
  18. </p>
  19. <h2>Example</h2>
  20. <div>[example:webgl_helpers WebGL / helpers]</div>
  21. <div>[example:webgl_loader_nrrd WebGL / loader / nrrd]</div>
  22. <div>[example:webgl_buffergeometry_drawcalls advanced / buffergeometry / drawcalls]</div>
  23. <code>
  24. // Creating the object whose bounding box we want to compute
  25. var sphereGeom = new THREE.SphereGeometry();
  26. var sphereObject = new THREE.Mesh(
  27. sphereGeom,
  28. new THREE.MeshBasicMaterial( 0xff0000 )
  29. );
  30. // Creating the helper and displaying it in the scene
  31. var helper = new THREE.BoxHelper( sphereObject, 0xffff00 );
  32. scene.add( helper );
  33. // Creating the actual bounding box
  34. // (on which we can test intersection with other Box3 objects)
  35. sphereObject.geometry.computeBoundingBox();
  36. var BBox = new THREE.Box3(
  37. sphereObject.geometry.boundingBox.min,
  38. sphereObject.geometry.boundingBox.max
  39. );
  40. // Moving the sphere
  41. sphereObject.position.set( 7, 7, 7 );
  42. // Updating both the bounding box and the helper
  43. // (to repeat each time the object is moved, rotated or scaled)
  44. BBox.copy( sphereObject.geometry.boundingBox ).applyMatrix4( sphereObject.matrixWorld );
  45. helper.update();
  46. </code>
  47. <h2>Constructor</h2>
  48. <h3>[name]( [param:Object3D object], [param:Color color] )</h3>
  49. <p>
  50. [page:Object3D object] -- (optional) the object3D to show the world-axis-aligned boundingbox.<br />
  51. [page:Color color] -- (optional) hexadecimal value that defines the box's color. Default is 0xffff00.<br /><br />
  52. Creates a new wireframe box that bounds the passed object. Internally this uses [page:Box3.setFromObject]
  53. to calculate the dimensions. Note that this includes any children.
  54. </p>
  55. <h2>Properties</h2>
  56. <p>See the base [page:LineSegments] class for common properties.</p>
  57. <h2>Methods</h2>
  58. <p>See the base [page:LineSegments] class for common methods.</p>
  59. <h3>[method:null update]()</h3>
  60. <p>
  61. Updates the helper's geometry to match the dimensions
  62. of the object, including any children. See [page:Box3.setFromObject].
  63. </p>
  64. <h3>[method:BoxHelper setFromObject]( [param:Object3D object] )</h3>
  65. <p>
  66. [page:Object3D object] - [page:Object3D] to create the helper of.<br /><br />
  67. Updates the wireframe box for the passed object.
  68. </p>
  69. <h2>Source</h2>
  70. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  71. </body>
  72. </html>