制作一個IK定位骨骼模塊

之前研究過這個問題,這是當(dāng)時我計算極向量位置的解決方案
def computePolePos(ik_joints, **kwargs): offset_factor = kwargs.pop("offset", 5.0) coordinates = [] for joint in ik_joints: joint_pos = pm.xform(joint, q=True, ws=True, t=True) coordinates.append(joint_pos) point_A = om.MPoint(coordinates[0][0], coordinates[0][1], coordinates[0][2], 1) point_B = om.MPoint(coordinates[1][0], coordinates[1][1], coordinates[1][2], 1) point_C = om.MPoint(coordinates[2][0], coordinates[2][1], coordinates[2][2], 1) vec_AC = om.MVector(point_C - point_A) vec_AB = om.MVector(point_B - point_A) cos = (vec_AC * vec_AB) / (vec_AC.length() * vec_AB.length()) len_AD = vec_AB.length() * cos factor = len_AD / vec_AC.length() vec_AD = factor * vec_AC vec_DB = vec_AB - vec_AD loc = pm.spaceLocator() loc.visibility.set(False) pm.matchTransform(loc, ik_joints[1], pos=True) loc_pos = loc.getTranslation(space='world') loc.setTranslation(loc_pos + (offset_factor * dt.Vector(*vec_DB)), space='world') return loc
標(biāo)簽: