public static MDagPath AddRPIKPole(MDagPath middleDagPath = null) { if (middleDagPath == null) { middleDagPath = BasicFunc.GetSelectedDagPath(0); if (middleDagPath == null) { Debug.Log("please select middle joint"); return(null); } } MDagPath rootDagPath = new MDagPath(), endDagPath = new MDagPath(); MFnIkJoint middleJoint = new MFnIkJoint(middleDagPath); if (middleJoint.parentCount > 0) { MDagPath.getAPathTo(middleJoint.parent(0), rootDagPath); MFnIkJoint rootJoint = new MFnIkJoint(rootDagPath); if (middleJoint.childCount > 0) { MDagPath.getAPathTo(middleJoint.child(0), endDagPath); MFnIkJoint endJoint = new MFnIkJoint(endDagPath); MVector rootPos = rootJoint.getTranslation(MSpace.Space.kWorld); MVector middlePos = middleJoint.getTranslation(MSpace.Space.kWorld); MVector endPos = endJoint.getTranslation(MSpace.Space.kWorld); //double len0 = (middlePos - rootPos).length; //double len1 = (endPos - middlePos).length; MVector fitLinePos = (rootPos + endPos) * 0.5; MVector direct_pole = middlePos - fitLinePos; MVector direct_fitLine = rootPos - endPos; MVector direct_projectPolePos = BasicFunc.VerticalProject(direct_pole, direct_fitLine).normal; //MVector nmPos = (rootPos * len0 + endPos * len1) * (1 / (len0 + len1)); float factor = (float)((rootPos - endPos).length / 3); MVector polePos = factor * direct_projectPolePos + middlePos; string locName = "loc_" + rootJoint.name + "_" + endJoint.name; return(BasicFunc.CreateLocator(polePos, locName)); } } return(null); }