public static MDagPath AddParentCircle(MDagPath targetDagPath, bool createParallelGrp) { string ctlName = "ctl_" + targetDagPath.partialPathName; MDagPath ctlDagPath = BasicFunc.CreateCircle(ctlName); ctlName = ctlDagPath.fullPathName; MFnTransform targetTrans = new MFnTransform(targetDagPath); if (createParallelGrp) { MFnTransform parellelGrpTrans = new MFnTransform(AddEmptyGroup(new MFnTransform(targetTrans.parent(0)))); parellelGrpTrans.setTranslation(targetTrans.getTranslation(MSpace.Space.kTransform), MSpace.Space.kTransform); //Debug.Log("finalLocalPos:"+BasicFunc.ToCMDSParamStr(parellelGrpTrans.getTranslation(MSpace.kTransform))); MEulerRotation rot = new MEulerRotation(); targetTrans.getRotation(rot); parellelGrpTrans.setRotation(rot); SetTransformParent(ctlName, parellelGrpTrans.fullPathName); } MFnTransform circleTransform = new MFnTransform(ctlDagPath); circleTransform.setTranslation(new MVector(0, 0, 0), MSpace.Space.kTransform); circleTransform.setRotation(new MEulerRotation(0, 90 / ConstantValue.DPR, 0)); FreezeTransform(circleTransform); return(ctlDagPath); }
public static void BeautifulPole(MDagPath middleDag = null, bool clearFlag_x = true, bool clearFlag_y = true, bool clearFlag_z = true, bool useMoveSkinJointsTool = true) { if (middleDag == null || middleDag.node.isNull) { middleDag = BasicFunc.GetSelectedDagPath(0); if (middleDag == null || middleDag.node.isNull) { Debug.Log("please select middle joint"); return; } } MFnTransform middleTrans = new MFnTransform(middleDag); if (middleTrans.parentCount == 0 || middleTrans.childCount == 0) { return; } MDagPath parentDag = MDagPath.getAPathTo(middleTrans.parent(0)); MDagPath childDag = MDagPath.getAPathTo(middleTrans.child(0)); MFnTransform parentTrans = new MFnTransform(parentDag); MFnTransform childTrans = new MFnTransform(childDag); MVector parentWorldPos = parentTrans.getTranslation(MSpace.Space.kWorld); MVector middleWorldPos = middleTrans.getTranslation(MSpace.Space.kWorld); MVector childWorldPos = childTrans.getTranslation(MSpace.Space.kWorld); //MVector vec_middleToParent = parentWorldPos - middleWorldPos; //MVector vec_childToMiddle = middleWorldPos - childWorldPos; //MVector verticalBack = BasicFunc.Cross(vec_middleToParent, vec_childToMiddle); float length0 = (float)(middleWorldPos - parentWorldPos).length; float length1 = (float)(middleWorldPos - childWorldPos).length; MVector posByWeight = BasicFunc.Lerp(parentWorldPos, childWorldPos, length0 / (length0 + length1)); if (useMoveSkinJointsTool) { MoveSkinJointsTool(middleDag); } //middleTrans.setTranslation(posByWeight, MSpace.Space.kWorld); if (!clearFlag_x) { posByWeight.x = middleWorldPos.x; } if (!clearFlag_y) { posByWeight.y = middleWorldPos.y; } if (!clearFlag_z) { posByWeight.z = middleWorldPos.z; } middleTrans.setTranslation(posByWeight, MSpace.Space.kWorld); childTrans.setTranslation(childWorldPos, MSpace.Space.kWorld); //MFnIkJoint middleJoint = new MFnIkJoint(middleDag); }
public static MDagPath CreateLocator(MVector worldPos, string locatorName) { string cmdStr = "cmds.spaceLocator(n='" + locatorName + "')"; locatorName = SubUShell(MGlobal.executePythonCommandStringResult(cmdStr)); MDagPath locDagPath = BasicFunc.GetDagPathByName(locatorName); MFnTransform locatorTrans = new MFnTransform(locDagPath); //Debug.Log(locatorName+"dag:"+locDagPath.fullPathName); locatorTrans.setTranslation(worldPos, MSpace.Space.kWorld); return(locDagPath); }
public static MDagPath AddChildCircle(MDagPath targetDagPath) { string ctlName = "ctl_" + targetDagPath.partialPathName; MDagPath ctlDagPath = BasicFunc.CreateCircle(ctlName); ctlName = ctlDagPath.fullPathName; SetTransformParent(ctlName, targetDagPath.fullPathName); MFnTransform circleTransform = new MFnTransform(ctlDagPath); circleTransform.setTranslation(new MVector(0, 0, 0), MSpace.Space.kObject); circleTransform.setRotation(new MEulerRotation(0, 90 / ConstantValue.DPR, 0)); FreezeTransform(circleTransform); return(ctlDagPath); }
public static void ClearTransform(MFnTransform targetTransform, bool clearPos = true, bool clearPivotRot = true, bool clearPivotScale = true) { if (clearPos) { targetTransform.setTranslation(MVector.zero, MSpace.Space.kObject); } if (clearPivotRot) { targetTransform.setRotatePivotTranslation(MVector.zero, MSpace.Space.kObject); } if (clearPivotScale) { targetTransform.setScalePivotTranslation(MVector.one, MSpace.Space.kObject); } }
public static List <MDagPath> AddBonesCTL(MSelectionList jointList = null, MFnTransform parentTrans = null) { if (jointList == null) { jointList = BasicFunc.GetSelectedList(); } if (parentTrans == null) { parentTrans = new MFnTransform(BasicFunc.CreateEmptyGroup("grp_bonesCTL")); } if (jointList.length == 0) { return(null); } List <MDagPath> jointDags = new List <MDagPath>(); for (int i = 0; i < jointList.length; i++) { MDagPath dag = new MDagPath(); jointList.getDagPath((uint)i, dag); jointDags.Add(dag); } int count = jointDags.Count; MFnTransform[] jointTrans = new MFnTransform[count]; MFnTransform[] jointParentTrans = new MFnTransform[count]; for (int i = 0; i < jointDags.Count; i++) { jointTrans[i] = new MFnTransform(jointDags[i]); jointParentTrans[i] = new MFnTransform(MDagPath.getAPathTo(jointTrans[i].parent(0))); } MVector[] jointWorldPositions = new MVector[jointDags.Count]; MVector centerPos = MVector.zero; for (int i = 0; i < count; i++) { jointWorldPositions[i] = jointTrans[i].getTranslation(MSpace.Space.kWorld); centerPos += jointWorldPositions[i]; } centerPos = centerPos * (1.0f / count); double[] minDist_y = new double[count]; double[] minDist_x = new double[count]; if (count > 1) { for (int i = 0; i < count; i++) { double closestY = double.MaxValue, closestX = double.MaxValue; //int minDistIndex = 0; for (int j = 0; j < count; j++) { if (i == j) { continue; } MVector direct = jointWorldPositions[i] - jointWorldPositions[j]; direct.x = Math.Abs(direct.x); direct.y = Math.Abs(direct.y); if (direct.x >= direct.y) { if (direct.x < closestX) { closestX = direct.x; //minDistIndex = j; } } if (direct.y >= direct.x) { if (direct.y < closestY) { closestY = direct.y; } } } minDist_y[i] = closestY; minDist_x[i] = closestX; } } else { minDist_x[0] = 1; minDist_y[0] = 1; } List <MDagPath> curves = new List <MDagPath>(); for (int i = 0; i < count; i++) { float width = (float)minDist_x[i] / 2, height = (float)minDist_y[i] / 2; MDagPath curve = BasicFunc.CreateCTL_Square("ctl_" + jointDags[i].partialPathName, height, width); MFnTransform curveTrans = new MFnTransform(curve); BasicFunc.SetTransformParent(curveTrans, parentTrans); curveTrans.setTranslation(jointWorldPositions[i] - centerPos, MSpace.Space.kTransform); BasicFunc.FreezeTransform(curveTrans); BasicFunc.SetTranslateLimit(curveTrans, -width / 2, -height / 2, 0, width / 2, height / 2, 0); MPlug plug_curveTX = curveTrans.findPlug(ConstantValue.plugName_tx); MPlug plug_curveTY = curveTrans.findPlug(ConstantValue.plugName_ty); MPlug plug_jointRY = jointParentTrans[i].findPlug(ConstantValue.plugName_ry); MPlug plug_jointRZ = jointParentTrans[i].findPlug(ConstantValue.plugName_rz); BindAttr.ProjectPlug(plug_curveTX, plug_jointRY, -width / 2, width / 2, -45, 45); BindAttr.ProjectPlug(plug_curveTY, plug_jointRZ, -height / 2, height / 2, -45, 45); curves.Add(curve); } return(curves); }