Refactor MaterialAnimator to replace sphereRef with materialRef for clarity and consistency
This commit is contained in:
parent
406b52b0d8
commit
2b4153f520
|
@ -10,7 +10,7 @@ type MaterialAnimatorProps = {
|
|||
};
|
||||
|
||||
export default function MaterialAnimator({ ikSolver, armBot, currentPhase }: Readonly<MaterialAnimatorProps>) {
|
||||
const sphereRef = useRef<any>(null);
|
||||
const materialRef = useRef<any>(null);
|
||||
const [isRendered, setIsRendered] = useState<boolean>(false);
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -22,7 +22,7 @@ export default function MaterialAnimator({ ikSolver, armBot, currentPhase }: Rea
|
|||
}, [currentPhase]);
|
||||
|
||||
useFrame(() => {
|
||||
if (!ikSolver || !sphereRef.current) return;
|
||||
if (!ikSolver || !materialRef.current) return;
|
||||
|
||||
const boneTarget = ikSolver.mesh.skeleton.bones.find((b: any) => b.name === "Bone004");
|
||||
const bone = ikSolver.mesh.skeleton.bones.find((b: any) => b.name === "Effector");
|
||||
|
@ -39,17 +39,16 @@ export default function MaterialAnimator({ ikSolver, armBot, currentPhase }: Rea
|
|||
// Calculate direction
|
||||
const direction = new THREE.Vector3();
|
||||
direction.subVectors(boneWorldPos, boneTargetWorldPos).normalize();
|
||||
const downwardDirection = direction.clone().negate();
|
||||
|
||||
const adjustedPosition = boneWorldPos.clone().addScaledVector(downwardDirection, -0.01);
|
||||
const adjustedPosition = boneWorldPos.clone().addScaledVector(direction, 0.01);
|
||||
|
||||
//set position
|
||||
sphereRef.current.position.copy(adjustedPosition);
|
||||
materialRef.current.position.copy(adjustedPosition);
|
||||
|
||||
// Set rotation
|
||||
const worldQuaternion = new THREE.Quaternion();
|
||||
bone.getWorldQuaternion(worldQuaternion);
|
||||
sphereRef.current.quaternion.copy(worldQuaternion);
|
||||
materialRef.current.quaternion.copy(worldQuaternion);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -58,7 +57,7 @@ export default function MaterialAnimator({ ikSolver, armBot, currentPhase }: Rea
|
|||
{isRendered && (
|
||||
<MaterialModel
|
||||
materialId={armBot.currentAction?.materialId ?? ''}
|
||||
matRef={sphereRef}
|
||||
matRef={materialRef}
|
||||
materialType={armBot.currentAction?.materialType ?? 'Default material'}
|
||||
/>
|
||||
)}
|
||||
|
|
Loading…
Reference in New Issue