1// SPDX-License-Identifier: GPL-2.0-only
2// Copyright (c) 2025-present FERS Contributors (see AUTHORS.md).
4import { useMemo, useRef } from 'react';
5import * as THREE from 'three';
6import { fersColors } from '@/theme';
7import { useDynamicScale } from '@/hooks/useDynamicScale';
9const BORESIGHT_LENGTH = 7; // Length of the arrow in world units.
12 * Renders a boresight arrow indicating the forward direction of an object.
13 * This component should be placed inside a <group> that has its rotation set
14 * to the object's orientation. The arrow points along the group's local -Z axis.
16export function BoresightArrow() {
17 const groupRef = useRef<THREE.Group>(null);
19 // Apply dynamic scaling
20 useDynamicScale(groupRef);
22 const arrowHelper = useMemo(() => {
23 const dir = new THREE.Vector3(0, 0, -1); // Points "forward" along local -Z axis.
24 const origin = new THREE.Vector3(0, 0, 0); // Arrow starts at the object's origin.
25 return new THREE.ArrowHelper(
29 fersColors.physics.boresight
33 // Use the <primitive> element to add the pre-built ArrowHelper object to the scene.
35 <group ref={groupRef}>
36 <primitive object={arrowHelper} />