import { useRef } from "react"; import { useFrame } from "@react-three/fiber"; import * as THREE from "three"; interface RepairBrokenPartHighlightProps { target: THREE.Object3D; } const _box = new THREE.Box3(); const _sphere = new THREE.Sphere(); const _worldPosition = new THREE.Vector3(); const _localPosition = new THREE.Vector3(); export function RepairBrokenPartHighlight({ target, }: RepairBrokenPartHighlightProps): React.JSX.Element { const groupRef = useRef(null); useFrame(({ clock }) => { const group = groupRef.current; if (!group) return; _box.setFromObject(target).getBoundingSphere(_sphere); _worldPosition.copy(_sphere.center); _localPosition.copy(_worldPosition); group.parent?.worldToLocal(_localPosition); group.position.copy(_localPosition); const pulse = 1 + Math.sin(clock.elapsedTime * 5) * 0.08; const radius = Math.max(_sphere.radius, 0.35) * pulse; group.scale.setScalar(radius); }); return ( ); }