ThreeJS Helper 1

ArrowHelper

A 3D arrow object for visualizing directions.

Code Example

const dir = new THREE.Vector3( 1, 2, 0 );


//normalize the direction vector (convert to vector of length 1)
dir.normalize();


const origin = new THREE.Vector3( 0, 0, 0 );
const length = 1;
const hex = 0xffff00;


const arrowHelper = new THREE.ArrowHelper( dir, origin, length, hex );
scene.add( arrowHelper );

Constructor

ArrowHelper(dir : Vector3, origin : Vector3, length : Number, hex : Number, headLength : Number, headWidth : Number )

dir -- direction from origin. Must be a unit vector.

origin -- Point at which the arrow starts.

length -- length of the arrow. Default is 1.

hex -- hexadecimal value to define color. Default is 0xffff00.

headLength -- The length of the head of the arrow. Default is 0.2 * length.

headWidth -- The width of the head of the arrow. Default is 0.2 * headLength.

Properties

See the base Object3D class for common properties.

.line : Line

Contains the line part of the arrowHelper.

.cone : Mesh

Contains the cone part of the arrowHelper.

Methods

See the base Object3D class for common methods.

.setColor (color : Color) : undefined

color -- The desired color.

Sets the color of the arrowHelper.

.setLength (length : Number, headLength : Number, headWidth : Number) : undefined

length -- The desired length.

headLength -- The length of the head of the arrow.

headWidth -- The width of the head of the arrow.

Sets the length of the arrowhelper.

.setDirection (dir : Vector3) : undefined

dir -- The desired direction. Must be a unit vector.

Sets the direction of the arrowhelper.

AxesHelper

An axis object to visualize the 3 axes in a simple way.

The X axis is red. The Y axis is green. The Z axis is blue.

Code Example

const axesHelper = new THREE.AxesHelper( 5 );
scene.add( axesHelper );

Constructor

AxesHelper( size : Number )

size -- (optional) size of the lines representing the axes. Default is 1.

Properties

See the base LineSegments class for common properties.

Methods

See the base LineSegments class for common methods.

.setColors ( xAxisColor : Color, yAxisColor : Color, zAxisColor : Color ) : this

Sets the axes colors to xAxisColor, yAxisColor, zAxisColor.

.dispose () : undefined

Disposes of the internally-created material and geometry used by this helper.

BoxHelper

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 the BoxHelper.update method when the object it's created from is transformed. Note that the object must have a BufferGeometry for this to work, so it won't work with Sprites.

Code Example

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 );

Constructor

BoxHelper( object : Object3D, color : Color )

object -- (optional) the object3D to show the world-axis-aligned boundingbox.

color -- (optional) hexadecimal value that defines the box's color. Default is 0xffff00.

Creates a new wireframe box that bounds the passed object. Internally this uses Box3.setFromObject to calculate the dimensions. Note that this includes any children.

Box3Helper

Helper object to visualize a Box3.

Code Example

const box = new THREE.Box3();
box.setFromCenterAndSize( new THREE.Vector3( 1, 1, 1 ), new THREE.Vector3( 2, 1, 3 ) );


const helper = new THREE.Box3Helper( box, 0xffff00 );
scene.add( helper );

Constructor

Box3Helper( box : Box3, color : Color )

box -- the Box3 to show.

color -- (optional) the box's color. Default is 0xffff00.

Creates a new wireframe box that represents the passed Box3.

Properties

See the base LineSegments class for common properties.

.box : Box3

The Box3 being visualized.

Methods

See the base LineSegments class for common methods.

.updateMatrixWorld ( force : Boolean ) : undefined

This overrides the method in the base Object3D class so that it also updates the wireframe box to the extent of the .box property.

CameraHelper

This helps with visualizing what a camera contains in its frustum.

It visualizes the frustum of a camera using a LineSegments.

Code Example

const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
const helper = new THREE.CameraHelper( camera );
scene.add( helper );

Constructor

CameraHelper( camera : Camera )

camera -- The camera to visualize.

This create a new CameraHelper for the specified camera.

Properties

See the base LineSegments class for common properties.

.camera : Camera

The camera being visualized.

.pointMap : Object

This contains the points used to visualize the camera.

.matrix : Object

Reference to the camera.matrixWorld.

.matrixAutoUpdate : Object

See Object3D.matrixAutoUpdate. Set to false here as the helper is using the camera's matrixWorld.

Methods

See the base LineSegments class for common methods.

.dispose () : undefined

Disposes of the internally-created material and geometry used by this helper.

.update () : undefined

Updates the helper based on the projectionMatrix of the camera.

DirectionalLightHelper

Helper object to assist with visualizing a DirectionalLight's effect on the scene. This consists of plane and a line representing the light's position and direction.

Code Example

const light = new THREE.DirectionalLight( 0xFFFFFF );
const helper = new THREE.DirectionalLightHelper( light, 5 );
scene.add( helper );

Constructor

DirectionalLightHelper( light : DirectionalLight, size : Number, color : Hex )

light-- The light to be visualized.

size -- (optional) dimensions of the plane. Default is 1.

color -- (optional) if this is not the set the helper will take the color of the light.

Properties

See the base Object3D class for common properties.

.lightPlane : Line

Contains the line mesh showing the location of the directional light.

.light : DirectionalLight

Reference to the directionalLight being visualized.

.matrix : Object

Reference to the light's matrixWorld.

.matrixAutoUpdate : Object

See Object3D.matrixAutoUpdate. Set to false here as the helper is using the light's matrixWorld.

.color : hex

The color parameter passed in the constructor. Default is undefined. If this is changed, the helper's color will update the next time update is called.

Methods

See the base Object3D class for common properties.

.dispose () : undefined

Dispose of the directionalLightHelper.

.update () : undefined

Updates the helper to match the position and direction of the directionalLight being visualized.

GridHelper

The GridHelper is an object to define grids. Grids are two-dimensional arrays of lines.

Code Example

const size = 10;
const divisions = 10;


const gridHelper = new THREE.GridHelper( size, divisions );
scene.add( gridHelper );

Constructor

GridHelper( size : number, divisions : Number, colorCenterLine : Color, colorGrid : Color )

size -- The size of the grid. Default is 10.

divisions -- The number of divisions across the grid. Default is 10.

colorCenterLine -- The color of the centerline. This can be a Color, a hexadecimal value and an CSS-Color name. Default is 0x444444

colorGrid -- The color of the lines of the grid. This can be a Color, a hexadecimal value and an CSS-Color name. Default is 0x888888

Creates a new GridHelper of size 'size' and divided into 'divisions' segments per side. Colors are optional.


Related Topics

ThreeJS InterleavedBuffer

The term "interleaved" refers to the packing of multiple attributes, possibly of different types (e.g., position, normal, uv, colour) into a single array buffer. Constructor InterleavedBuffer( array : TypedArray, stride : Integer...

3 minutes read.

ThreeJS Raycaster

This class is intended to help with raycasting. Raycasting is used for a variety of purposes, including mouse picking (determining which objects in 3D space the mouse is over). Code Example const...

4 minutes read.

ThreeJS Creating VR Content

This article gives a quick introduction of the main components of a three.js-based web-based VR application. Workflow      First, you have to include VRButton.js into your project. import { VRButton } from...

1 minute read.

ThreeJS Audio

It is used to create a non-positional (global ) audio object. Code Example: // create an AudioListener and add it to the camera const listener = new THREE.AudioListener(); camera.add( listener ); // create a global...

6 minutes read.

ThreeJS Helper 1

ArrowHelper A 3D arrow object for visualizing directions. Code Example const dir = new THREE.Vector3( 1, 2, 0 ); //normalize the direction vector (convert to vector of length 1) dir.normalize(); const origin = new THREE.Vector3( 0,...

5 minutes read.

ThreeJS BufferAttribute

This class stores data for an attribute associated with a BufferGeometry (such as vertex positions, face indices, normals, colours, UVs, and any custom attributes), allowing for more efficient data passing...

4 minutes read.

ThreeJS Loaders 2

ImageBitmapLoader A loader that converts an image to an ImageBitmap. An ImageBitmap provides an asynchronous and resource-efficient path for preparing textures for WebGL rendering. ImageBitmapLoader, unlike FileLoader, does not prevent multiple concurrent...

8 minutes read.

ThreeJS Uniform

Uniforms are global GLSL variables. They are passed to shader programs. Code Example When declaring a uniform of a ShaderMaterial, it is declared by value or by object. uniforms: { time: { value: 1.0...

2 minutes read.

ThreeJS Object3D

This is the base class for most three.js objects, and it provides a set of properties and methods for manipulating objects in 3D space. It should be noted that this can...

9 minutes read.

ThreeJS Material - Mesh

MeshBasicMaterial A material for drawing geometries in a simple shaded (flat or wireframe) way. This material is not affected by lights. Constructor MeshBasicMaterial( parameters : Object ) parameters - (optional) an object with one or...

24 minutes read.

ThreeJS Lines and Texts

Drawing Lines Let's say you want to draw a line or a circle, not a wireframe Mesh. First, we need to set up the renderer, scene, and camera. Here is the...

3 minutes read.

ThreeJS Geometries-1

BoxGeometry BoxGeometry is a geometry class for a rectangular cuboid with a given 'width', 'height', and 'depth'. On creation, the cuboid is centered on the origin, with each edge parallel to...

7 minutes read.

ThreeJS Property Binding and Mixer

PropertyBinding Internally, this holds a reference to real property in the scene graph. Constructor PropertyBinding( rootNode : Object3D, path, parsedPath ) -- rootNode: -- path -- parsedPath (optional) Properties The properties are as follows: .path : Number.parsedPath...

2 minutes read.

ThreeJS Curve

An abstract base class for creating a Curve object with interpolation methods. CurvePath is an array of Curves. Constructor Curve() This constructor creates a new Curve. Properties .arcLengthDivisions : Integer This value determines the amount of...

13 minutes read.

ThreeJS Installation

You can use npm and modern build tools to install three.js, or you can get started quickly with static hosting or a CDN. Installing from npm is the best option...

4 minutes read.

ThreeJS AnimationClip

An AnimationClip is a group of keyframe tracks that may be reused to depict an animation. The "Animation System" page in the "Next Steps" part of the handbook provides an overview...

2 minutes read.

ThreeJS Objects

Bone A bone that is part of a Skeleton. The skeleton in turn is used by the SkinnedMesh. Bones are almost identical to a blank Object3D. Code Example const root = new THREE.Bone(); const...

12 minutes read.

ThreeJS Testing with npm

This article explains how to install three.js in a node.js environment so that automated tests may be run. Tests can be done manually or with the help of automated CI...

4 minutes read.

ThreeJS Animation Systems

You may animate many aspects of your models with the three.js animation system, including the bones of a skinned and rigged model, morph targets, multiple material properties (colours, opacity, booleans),...

3 minutes read.

ThreeJS BufferGeometry

A mesh, line, or point geometry representation. Included within buffers are vertex positions, face indices, normals, colours, UVs, and custom attributes, lowering the cost of passing all of this data...

5 minutes read.