path helper added
This commit is contained in:
parent
fe57e6c873
commit
c95f140d30
|
@ -91,7 +91,7 @@ function RoboticArmAnimator({
|
||||||
const bone = ikSolver.mesh.skeleton.bones.find(
|
const bone = ikSolver.mesh.skeleton.bones.find(
|
||||||
(b: any) => b.name === targetBone
|
(b: any) => b.name === targetBone
|
||||||
);
|
);
|
||||||
bone.position.copy(restPosition);
|
// bone.position.copy(restPosition);
|
||||||
ikSolver.update();
|
ikSolver.update();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ function RoboticArmAnimator({
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* {currentPath.length > 0 && (
|
{/* {currentPath.length > 0 && (
|
||||||
<>
|
<mesh rotation={armBot.rotation}>
|
||||||
<Line points={currentPath} color="green" lineWidth={3} />
|
<Line points={currentPath} color="green" lineWidth={3} />
|
||||||
{currentPath.map((point, index) => (
|
{currentPath.map((point, index) => (
|
||||||
<mesh key={index} position={point} rotation={armBot.rotation}>
|
<mesh key={index} position={point} rotation={armBot.rotation}>
|
||||||
|
@ -108,8 +108,33 @@ function RoboticArmAnimator({
|
||||||
<meshStandardMaterial color="red" />
|
<meshStandardMaterial color="red" />
|
||||||
</mesh>
|
</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>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,18 +3,19 @@ import * as THREE from "three";
|
||||||
import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader";
|
import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader";
|
||||||
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
|
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
|
||||||
import { clone } from "three/examples/jsm/utils/SkeletonUtils";
|
import { clone } from "three/examples/jsm/utils/SkeletonUtils";
|
||||||
import { useLoader, useThree } from "@react-three/fiber";
|
import { useLoader, useThree } from "@react-three/fiber";
|
||||||
import { CCDIKSolver, CCDIKHelper, } from "three/examples/jsm/animation/CCDIKSolver";
|
import { CCDIKSolver, CCDIKHelper, } from "three/examples/jsm/animation/CCDIKSolver";
|
||||||
|
import { TransformControls } from '@react-three/drei';
|
||||||
|
|
||||||
type IKInstanceProps = {
|
type IKInstanceProps = {
|
||||||
modelUrl: string;
|
modelUrl: string;
|
||||||
ikSolver: any;
|
ikSolver: any;
|
||||||
setIkSolver: any
|
setIkSolver: any
|
||||||
armBot: any;
|
armBot: any;
|
||||||
groupRef: React.RefObject<THREE.Group>;
|
groupRef: any;
|
||||||
};
|
};
|
||||||
function IKInstance({ modelUrl, setIkSolver, ikSolver, armBot, groupRef}: IKInstanceProps) {
|
function IKInstance({ modelUrl, setIkSolver, ikSolver, armBot, groupRef }: IKInstanceProps) {
|
||||||
const {scene}=useThree()
|
const { scene } = useThree()
|
||||||
const gltf = useLoader(GLTFLoader, modelUrl, (loader) => {
|
const gltf = useLoader(GLTFLoader, modelUrl, (loader) => {
|
||||||
const draco = new DRACOLoader();
|
const draco = new DRACOLoader();
|
||||||
draco.setDecoderPath("https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/libs/draco/");
|
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 cloned = useMemo(() => clone(gltf?.scene), [gltf]);
|
||||||
const targetBoneName = "Target";
|
const targetBoneName = "Target";
|
||||||
const skinnedMeshName = "link_0";
|
const skinnedMeshName = "link_0";
|
||||||
|
const [selectedArm, setSelectedArm] = useState<THREE.Group>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!gltf) return;
|
if (!gltf) return;
|
||||||
|
@ -65,6 +67,9 @@ function IKInstance({ modelUrl, setIkSolver, ikSolver, armBot, groupRef}: IKInst
|
||||||
setIkSolver(solver);
|
setIkSolver(solver);
|
||||||
|
|
||||||
const helper = new CCDIKHelper(OOI.Skinned_Mesh, iks, 0.05)
|
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)
|
scene.add(helper)
|
||||||
|
|
||||||
|
@ -73,7 +78,10 @@ function IKInstance({ modelUrl, setIkSolver, ikSolver, armBot, groupRef}: IKInst
|
||||||
|
|
||||||
return (
|
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
|
<primitive
|
||||||
uuid={"ArmBot-X200"}
|
uuid={"ArmBot-X200"}
|
||||||
object={cloned}
|
object={cloned}
|
||||||
|
@ -81,6 +89,7 @@ function IKInstance({ modelUrl, setIkSolver, ikSolver, armBot, groupRef}: IKInst
|
||||||
name={`arm-bot11`}
|
name={`arm-bot11`}
|
||||||
/>
|
/>
|
||||||
</group>
|
</group>
|
||||||
|
{/* {selectedArm && <TransformControls object={selectedArm} />} */}
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue