path helper added

This commit is contained in:
Gomathi 2025-04-30 10:30:30 +05:30
parent fe57e6c873
commit c95f140d30
2 changed files with 42 additions and 8 deletions

View File

@ -91,7 +91,7 @@ function RoboticArmAnimator({
const bone = ikSolver.mesh.skeleton.bones.find(
(b: any) => b.name === targetBone
);
bone.position.copy(restPosition);
// bone.position.copy(restPosition);
ikSolver.update();
};
@ -100,7 +100,7 @@ function RoboticArmAnimator({
return (
<>
{/* {currentPath.length > 0 && (
<>
<mesh rotation={armBot.rotation}>
<Line points={currentPath} color="green" lineWidth={3} />
{currentPath.map((point, index) => (
<mesh key={index} position={point} rotation={armBot.rotation}>
@ -108,8 +108,33 @@ function RoboticArmAnimator({
<meshStandardMaterial color="red" />
</mesh>
))}
</>
</mesh>
)} */}
{curvePoints && (
<mesh rotation={armBot.rotation}>
<Line
points={curvePoints.map(p => [p.x, p.y, p.z])}
color="green"
lineWidth={5}
dashed={false}
/>
{currentPath.length >= 1 && (
<>
{/* First point */}
<mesh position={currentPath[0]} rotation={armBot.rotation}>
<sphereGeometry args={[0.1, 16, 16]} />
<meshStandardMaterial color="red" />
</mesh>
{/* Last point */}
<mesh position={currentPath[currentPath.length - 1]} rotation={armBot.rotation}>
<sphereGeometry args={[0.1, 16, 16]} />
<meshStandardMaterial color="red" />
</mesh>
</>
)}
</mesh>
)}
</>
);
}

View File

@ -5,16 +5,17 @@ import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
import { clone } from "three/examples/jsm/utils/SkeletonUtils";
import { useLoader, useThree } from "@react-three/fiber";
import { CCDIKSolver, CCDIKHelper, } from "three/examples/jsm/animation/CCDIKSolver";
import { TransformControls } from '@react-three/drei';
type IKInstanceProps = {
modelUrl: string;
ikSolver: any;
setIkSolver: any
armBot: any;
groupRef: React.RefObject<THREE.Group>;
groupRef: any;
};
function IKInstance({ modelUrl, setIkSolver, ikSolver, armBot, groupRef}: IKInstanceProps) {
const {scene}=useThree()
function IKInstance({ modelUrl, setIkSolver, ikSolver, armBot, groupRef }: IKInstanceProps) {
const { scene } = useThree()
const gltf = useLoader(GLTFLoader, modelUrl, (loader) => {
const draco = new DRACOLoader();
draco.setDecoderPath("https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/libs/draco/");
@ -23,6 +24,7 @@ function IKInstance({ modelUrl, setIkSolver, ikSolver, armBot, groupRef}: IKInst
const cloned = useMemo(() => clone(gltf?.scene), [gltf]);
const targetBoneName = "Target";
const skinnedMeshName = "link_0";
const [selectedArm, setSelectedArm] = useState<THREE.Group>();
useEffect(() => {
if (!gltf) return;
@ -65,6 +67,9 @@ function IKInstance({ modelUrl, setIkSolver, ikSolver, armBot, groupRef}: IKInst
setIkSolver(solver);
const helper = new CCDIKHelper(OOI.Skinned_Mesh, iks, 0.05)
groupRef.current.add(helper);
console.log('OOI.Target_Bone: ', OOI.Target_Bone);
setSelectedArm(OOI.Target_Bone);
scene.add(helper)
@ -73,7 +78,10 @@ function IKInstance({ modelUrl, setIkSolver, ikSolver, armBot, groupRef}: IKInst
return (
<>
<group ref={groupRef} position={armBot.position} rotation={armBot.rotation}>
<group ref={groupRef} position={armBot.position} rotation={armBot.rotation} onClick={() =>{
setSelectedArm(groupRef.current?.getObjectByName(targetBoneName))
}
}>
<primitive
uuid={"ArmBot-X200"}
object={cloned}
@ -81,6 +89,7 @@ function IKInstance({ modelUrl, setIkSolver, ikSolver, armBot, groupRef}: IKInst
name={`arm-bot11`}
/>
</group>
{/* {selectedArm && <TransformControls object={selectedArm} />} */}
</>
)
}