Capítulo 320 de 859

Chapter 320: BoxHelper

Core Idea

Helper object to graphically show the world-axis-aligned bounding box around an object. The actual bounding box is handled with Box3, this is just a visual helper for debugging. It can be automatically resized with BoxHelper#update when the object it's created from is transformed. Note that the object must have a geometry for this to work, so it won't work with sprites.

Key Concepts

  • object : Object3D: The 3D object being visualized.

Code Examples

const sphere = new THREE.SphereGeometry();
const object = new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( 0xff0000 ) );
const box = new THREE.BoxHelper( object, 0xffff00 );
scene.add( box );
  • What it demonstrates: Typical usage of BoxHelper.

Reference Tables

Constructor

Signature
`new BoxHelper( object : Object3D, color : number

Properties

PropertyDescription
.object : Object3DThe 3D object being visualized.

Methods

MethodDescription
.dispose()Frees the GPU-related resources allocated by this instance. Call this method whenever this instance is no longer used in your app.
.setFromObject( object : Object3D ) : BoxHelperUpdates the wireframe box for the passed object.
.update()Updates the helper's geometry to match the dimensions of the object, including any children.

Key Takeaways

  1. BoxHelper extends: EventDispatcher → Object3D → Line → LineSegments
  2. Most relevant properties: object.
  3. Key methods: dispose, setFromObject, update.

Connects To

  • EventDispatcher: parent class
  • Object3D: parent class
  • Line: parent class
  • LineSegments: parent class
  • Source: src/helpers/BoxHelper.js