I’m working on a React Three Fiber project where I use the Html component from @react-three/drei to label equipment on 3D vessels. To keep the UI clean, I use the distanceFactor prop to maintain a constant screen-space size for the labels regardless of zoom.
The Issue:
When I double-click a label to focus the camera (tweening the OrbitControls target), the Html component stops scaling dynamically. It seems to “freeze” its size at the start of the transition, resulting in the label appearing incorrectly sized (Staying fixed in at present scale) even when the camera reaches the new zoom level.
Example Code:
function ModelLabel({ position, text }) {
const groupRef = useRef();
const handleDoubleClick = (e) => {
e.stopPropagation();
// Get current world position of the label
const worldPos = new Vector3();
groupRef.current.getWorldPosition(worldPos);
// Tween OrbitControls target to worldPos
tweenCameraTo(worldPos);
};
return (
<group ref={groupRef} position={position}>
<Html
center
distanceFactor={15}
onDoubleClick={handleDoubleClick}
>
<div className="label-style">{text}</div>
</Html>
</group>
);
}
Has anyone encountered this “frozen scale” issue when combining distanceFactor with camera animations? Is there a way to force the Html component to re-calculate its scale every frame during a transition?
Thanks in advance for any insights!