feat: Enhance IK handling in Model and IKInstance components with improved data structure and validation
This commit is contained in:
@@ -22,7 +22,7 @@ function IKInstance({ setIkSolver, armBot }: IKInstanceProps) {
|
||||
const trySetup = () => {
|
||||
const targetMesh = scene?.getObjectByProperty("uuid", armBot.modelUuid);
|
||||
|
||||
if (!targetMesh) {
|
||||
if (!targetMesh || !targetMesh.userData.iks || targetMesh.userData.iks.length < 1) {
|
||||
retryId = setTimeout(trySetup, 100);
|
||||
return;
|
||||
}
|
||||
@@ -33,34 +33,22 @@ function IKInstance({ setIkSolver, armBot }: IKInstanceProps) {
|
||||
if (n.name === skinnedMeshName) OOI.Skinned_Mesh = n;
|
||||
});
|
||||
if (!OOI.Target_Bone || !OOI.Skinned_Mesh) return;
|
||||
const iks = [
|
||||
{
|
||||
target: 7,
|
||||
effector: 6,
|
||||
links: [
|
||||
{
|
||||
index: 5,
|
||||
enabled: true,
|
||||
rotationMin: new THREE.Vector3(-Math.PI / 2, 0, 0),
|
||||
rotationMax: new THREE.Vector3(Math.PI / 2, 0, 0),
|
||||
},
|
||||
{
|
||||
index: 4,
|
||||
enabled: true,
|
||||
rotationMin: new THREE.Vector3(-Math.PI / 2, 0, 0),
|
||||
rotationMax: new THREE.Vector3(0, 0, 0),
|
||||
},
|
||||
{
|
||||
index: 3,
|
||||
enabled: true,
|
||||
rotationMin: new THREE.Vector3(0, 0, 0),
|
||||
rotationMax: new THREE.Vector3(2, 0, 0),
|
||||
},
|
||||
{ index: 1, enabled: true, limitation: new THREE.Vector3(0, 1, 0) },
|
||||
{ index: 0, enabled: false, limitation: new THREE.Vector3(0, 0, 0) },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const rawIks: IK[] = targetMesh.userData.iks;
|
||||
const iks = rawIks.map((ik) => ({
|
||||
target: ik.target,
|
||||
effector: ik.effector,
|
||||
links: ik.links.map((link) => ({
|
||||
index: link.index,
|
||||
enabled: link.enabled,
|
||||
rotationMin: link.rotationMin ? new THREE.Vector3(...link.rotationMin) : undefined,
|
||||
rotationMax: link.rotationMax ? new THREE.Vector3(...link.rotationMax) : undefined,
|
||||
limitation: link.limitation ? new THREE.Vector3(...link.limitation) : undefined,
|
||||
})),
|
||||
ringRadius: ik.ringRadius,
|
||||
maxheight: ik.maxheight,
|
||||
minheight: ik.minheight,
|
||||
}));
|
||||
|
||||
const solver = new CCDIKSolver(OOI.Skinned_Mesh, iks);
|
||||
setIkSolver(solver);
|
||||
|
||||
Reference in New Issue
Block a user