Files
Dwinzo_dev/app/src/modules/simulation/ui/arm/PickDropPoints.tsx

65 lines
1.4 KiB
TypeScript
Raw Normal View History

2025-04-28 12:26:31 +05:30
import React, { useRef } from "react";
import * as THREE from "three";
import { ThreeEvent } from "@react-three/fiber";
interface PickDropProps {
position: number[];
modelUuid: string;
pointUuid: string;
actionType: "pick" | "drop";
actionUuid: string;
gltfScene: THREE.Group;
2025-04-28 12:26:31 +05:30
handlePointerDown: (e: ThreeEvent<PointerEvent>) => void;
isSelected: boolean;
}
const PickDropPoints: React.FC<PickDropProps> = ({
position,
modelUuid,
pointUuid,
actionType,
actionUuid,
gltfScene,
handlePointerDown,
isSelected,
}) => {
2025-04-28 12:26:31 +05:30
const groupRef = useRef<THREE.Group>(null);
return (
<group
ref={groupRef}
position={
Array.isArray(position) && position.length === 3
? new THREE.Vector3(...position)
: new THREE.Vector3(0, 0, 0)
}
onPointerDown={(e) => {
e.stopPropagation(); // Prevent event bubbling
2025-04-28 12:26:31 +05:30
if (!isSelected) return;
handlePointerDown(e);
}}
userData={{ modelUuid, pointUuid, actionType, actionUuid }}
>
<primitive
object={(() => {
const cloned = gltfScene.clone();
cloned.traverse((child: any) => {
if (child.isMesh) {
child.userData = { modelUuid, pointUuid, actionType, actionUuid };
}
});
return cloned;
})()}
position={[0, 0, 0]}
2025-04-28 12:26:31 +05:30
scale={[0.5, 0.5, 0.5]}
/>
</group>
);
};
export default PickDropPoints;