UNPKG

2.98 kBTypeScriptView Raw
1import { BufferGeometry } from "../core/BufferGeometry.js";
2import { Object3D } from "../core/Object3D.js";
3import { LineBasicMaterial } from "../materials/LineBasicMaterial.js";
4import { ColorRepresentation } from "../math/Color.js";
5import { LineSegments } from "../objects/LineSegments.js";
6
7/**
8 * Helper object to graphically show the world-axis-aligned bounding box around an object
9 * @remarks
10 * The actual bounding box is handled with {@link THREE.Box3 | Box3}, this is just a visual helper for debugging
11 * It can be automatically resized with the {@link THREE.BoxHelper.update | BoxHelper.update} method when the object it's created from is transformed
12 * Note that the object must have a {@link THREE.BufferGeometry | BufferGeometry} for this to work, so it won't work with {@link Sprite | Sprites}.
13 * @example
14 * ```typescript
15 * const sphere = new THREE.SphereGeometry();
16 * const object = new THREE.Mesh(sphere, new THREE.MeshBasicMaterial(0xff0000));
17 * const box = new THREE.BoxHelper(object, 0xffff00);
18 * scene.add(box);
19 * ```
20 * @see Example: {@link https://threejs.org/examples/#webgl_helpers | WebGL / helpers}
21 * @see Example: {@link https://threejs.org/examples/#webgl_loader_nrrd | WebGL / loader / nrrd}
22 * @see Example: {@link https://threejs.org/examples/#webgl_buffergeometry_drawrange | WebGL / buffergeometry / drawrange}
23 * @see {@link https://threejs.org/docs/index.html#api/en/helpers/BoxHelper | Official Documentation}
24 * @see {@link https://github.com/mrdoob/three.js/blob/master/src/helpers/BoxHelper.js | Source}
25 */
26export class BoxHelper extends LineSegments<BufferGeometry, LineBasicMaterial> {
27 /**
28 * Creates a new wireframe box that bounds the passed object
29 * @remarks
30 * Internally this uses {@link THREE.Box3.setFromObject | Box3.setFromObject} to calculate the dimensions
31 * Note that this includes any children.
32 * @param object The object3D to show the world-axis-aligned bounding box.
33 * @param color Hexadecimal value that defines the box's color. Default `0xffff00`
34 */
35 constructor(object: Object3D, color?: ColorRepresentation);
36
37 /**
38 * A Read-only _string_ to check if `this` object type.
39 * @remarks Sub-classes will update this value.
40 * @override
41 * @defaultValue `BoxHelper`
42 */
43 override readonly type: string | "BoxHelper";
44
45 /**
46 * Updates the helper's geometry to match the dimensions of the object, including any children
47 * @remarks
48 * See {@link THREE.Box3.setFromObject | Box3.setFromObject}.
49 */
50 update(object?: Object3D): void;
51
52 /**
53 * Updates the wireframe box for the passed object.
54 * @param object {@link THREE.Object3D | Object3D} to create the helper of.
55 */
56 setFromObject(object: Object3D): this;
57
58 /**
59 * Frees the GPU-related resources allocated by this instance
60 * @remarks
61 * Call this method whenever this instance is no longer used in your app.
62 */
63 dispose(): void;
64}