AxesHelper
in JavaScriptIn JavaScript, three.js is a library that is built on top of WebGL and is used for rendering animations on the web.
When creating a scene, the developers use multiple built-in helpers to visualize some otherwise invisible aspects of the scene. In this Answer, we'll make use AxesHelper
to visualize the
const helper = new THREE.AxesHelper(size);
size
: This is the size of each axis and is of type Number
.The example below illustrates the use of AxesHelper
. The scene is also initialized with OrbitControls
so the camera can be panned around to view the scene from different angles. To read more on OrbitControls
, please follow this link.
The scene above consists of AxesHelper
and a sphere that we place at the coordinates
Line 35: This line of code initializes the OrbitControls
.
Lines 38–42: In these lines of code, we create a sphere shape and set its position according to the desired coordinates.
Line 46: We initialize our AxesHelper
and store the returned instance inside helper
.
Line 47: We add helper
to the scene so that we can visualize it.
By default, the red line is the -axis, the green is -axis, and the blue is -axis. The colors, however, can be changed using the .setColors()
method.