Description
After effects IK rig without any Plugin #ae #aftereffects
AE IK控制,无插件~
大小腿控制代码:
// === IK 设置变量(必须修改)===
cw = false; // true=顺时针弯曲,false=逆时针(腿部通常 false)
upper = true; // true=大腿,false=小腿
upperLimb = "大腿"; // 大腿图层名
lowerLimb = "小腿"; // 小腿图层名
extremity = "脚"; // 脚图层名
effector = "脚控制器"; // 控制器 Null 名
// === 以下代码无需修改 ===
function getWorldPos(theLayerName){
L = thisComp.layer(theLayerName);
return L.toWorld(L.anchorPoint);
}
A = getWorldPos(upperLimb);
B = getWorldPos(lowerLimb);
C = getWorldPos(extremity);
E = getWorldPos(effector);
a = length(B,C);
b = length(E,A);
c = length(A,B);
x = (b*b + c*c - a*a )/(2*b);
alpha = Math.acos(clamp(x/c,-1,1));
if (upper){
D = E - A;
delta = Math.atan2(D[1],D[0]);
result = radiansToDegrees(delta - (cw ? 1 : -1)*alpha);
V = B - A;
adj1 = radiansToDegrees(Math.atan2(V[1],V[0]));
result - adj1 + value;
}else{
y = b - x;
gamma = Math.acos(clamp(y/a,-1,1));
result = (cw ? 1 : -1)*radiansToDegrees(gamma + alpha);
V1 = B - A;
adj1 = radiansToDegrees(Math.atan2(V1[1],V1[0]));
V2 = C - B;
adj2 = radiansToDegrees(Math.atan2(V2[1],V2[0]));
result + adj1 - adj2 + value;
}
脚尖方向代码:
// === 新脚:彻底抵消所有父层旋转 + 始终指向脚尖控制器 ===
toe = thisComp.layer("脚尖控制器"); // ← 改成你脚尖控制器的真实名字
// 1. 计算世界空间下指向脚尖控制器的角度
targetWorld = toe.toWorld(toe.anchorPoint);
footWorld = toWorld(anchorPoint);
vec = targetWorld - footWorld;
desiredWorldAngle = radiansToDegrees(Math.atan2(vec[1], vec[0]));
// 2. 递归累加所有父层总旋转(你原来的函数)
function getAllTotalRotate(layerObj){
let totalRot = 0;
let curr = layerObj;
while(curr.hasParent){
totalRot += curr.parent.transform.rotation;
curr = curr.parent;
}
return totalRot;
}
// 3. 最终结果:期望的世界角度 - 所有父层旋转总和
desiredWorldAngle - getAllTotalRotate(thisLayer) + 180;