BoxHelper.html 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 show the world-axis-aligned bounding box around an object.
  15. It can be used in synergy with [page:Box3] items in order to easily compute the [link:https://en.wikipedia.org/wiki/Minimum_bounding_box Minimum Bounding Boxes] for objects, and use them for fast collision detection. See [page:Box3.intersect].
  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( sphereGeom, new THREE.MeshBasicMaterial( 0xff0000 ) );
  27. // Creating the helper and displaying it in the scene
  28. var helper = new THREE.BoxHelper( sphereObject, 0xffff00 );
  29. scene.add( helper );
  30. // Creating the actual bounding box (on which we can test intersection with other Box3 objects)
  31. var box3 = new THREE.Box3();
  32. // Shape and position the box after the helper
  33. box3.setFromObject( helper );
  34. // Let's move the sphere
  35. sphereObject.position.set( 7, 7, 7 );
  36. // Whenever the object is moved or rotated or scaled:
  37. helper.update();
  38. box3.setFromObject( helper );
  39. </code>
  40. <h2>Constructor</h2>
  41. <h3>[name]( [param:Object3D object], [param:Color color] )</h3>
  42. <p>
  43. [page:Object3D object] -- (optional) the object3D to show the world-axis-aligned boundingbox.<br />
  44. [page:Color color] -- (optional) hexadecimal value that defines the box's color. Default is 0xffff00.<br /><br />
  45. Creates a new wireframe box that bounds the passed object. Internally this uses [page:Box3.setFromObject]
  46. to calculate the dimensions. Note that this includes any children.
  47. </p>
  48. <h2>Properties</h2>
  49. <p>See the base [page:LineSegments] class for common properties.</p>
  50. <h2>Methods</h2>
  51. <p>See the base [page:LineSegments] class for common methods.</p>
  52. <h3>[method:null update]()</h3>
  53. <p>
  54. Updates the helper's geometry to match the dimensions
  55. of the object, including any children. See [page:Box3.setFromObject].
  56. </p>
  57. <h3>[method:BoxHelper setFromObject]( [param:Object3D object] )</h3>
  58. <p>
  59. [page:Object3D object] - [page:Object3D] to create the helper of.<br /><br />
  60. Updates the wireframe box for the passed object.
  61. </p>
  62. <h2>Source</h2>
  63. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  64. </body>
  65. </html>