Skip to content

axesHelper

Video Lecture

Section Video Links
axesHelper axesHelper axesHelper

Description

The axesHelper is an object to help visualize the 3 axes in a simple way. The X axis is red, the Y axis is green and the Z axis is blue.

The axesHelper is part of the Three.js core library, and also included by default as part of the Threejs intrinsic elements that are referenced when using the React Three Fiber canvas.

So we can use it straight it of the box.

Now, add,

<axesHelper />

to anywhere within the Canvas JSX tag, and it will work. Note the lowercase a in axesHelper.

The default length of the AxesHelper arms is one unit. You can pass in an argument to override the length.

E.g., make the arms 5 units long.

<axesHelper args={[5]} />

./src/App.jsx

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { Canvas } from '@react-three/fiber'
import Polyhedron from './Polyhedron'
import * as THREE from 'three'
import { Stats, OrbitControls } from '@react-three/drei'

export default function App() {
  const polyhedron = [
    new THREE.BoxGeometry(),
    new THREE.SphereGeometry(0.785398),
    new THREE.DodecahedronGeometry(0.785398),
  ]

  return (
    <Canvas camera={{ position: [0, 0, 3] }}>
      <Polyhedron position={[-0.75, -0.75, 0]} polyhedron={polyhedron} />
      <Polyhedron position={[0.75, -0.75, 0]} polyhedron={polyhedron} />
      <Polyhedron position={[-0.75, 0.75, 0]} polyhedron={polyhedron} />
      <Polyhedron position={[0.75, 0.75, 0]} polyhedron={polyhedron} />
      <OrbitControls />
      <axesHelper args={[5]} />
      <Stats />
    </Canvas>
  )
}

Working Example

<>
AxesHelper threejs.org sbedit.net

GitHub Branch

git clone https://github.com/Sean-Bradley/React-Three-Fiber-Boilerplate.git
cd React-Three-Fiber-Boilerplate
git checkout axesHelper
npm install
npm start

Comments