public static MFnBlendShapeDeformer GetBlendShape(MObject targetObject = null) { if (targetObject == null) { targetObject = BasicFunc.GetSelectedObject(0); } MDagPath dag_target = MDagPath.getAPathTo(targetObject); MFnDependencyNode node_target = new MFnDependencyNode(targetObject); MPlug plug = node_target.findPlug("inMesh"); Debug.Log("node_target:" + node_target.name + " plug:" + plug.name); MItDependencyGraph mit = new MItDependencyGraph(plug, MFn.Type.kBlendShape, MItDependencyGraph.Direction.kUpstream); //MDagPath dagPath = new MDagPath(); //MItDependencyNodes mitnode = new MItDependencyNodes(MFn.Type.kBlendShape); while (!mit.isDone) { MObject mo = mit.currentItem(); MFnDependencyNode dnode = new MFnDependencyNode(mo); Debug.Log("moing:" + dnode.absoluteName); if (mo.hasFn(MFn.Type.kBlendShape)) { Debug.Log("find blendshape"); return(new MFnBlendShapeDeformer(mo)); } mit.next(); } return(null); }
public static void BindShoulder(MSelectionList jointList = null) { if (jointList == null) { jointList = BasicFunc.GetSelectedList(MFn.Type.kJoint); } if (jointList.length != 4) { Debug.Log("please select joints"); return; } MDagPath dag_shoulder = new MDagPath(), dag_armRoot = new MDagPath(), dag_elbow = new MDagPath(), dag_wrist = new MDagPath(); jointList.getDagPath((uint)0, dag_shoulder); jointList.getDagPath((uint)1, dag_armRoot); jointList.getDagPath((uint)2, dag_elbow); jointList.getDagPath((uint)3, dag_wrist); //string shoulderIkName = JointProcess.AddIKHandle(dag_shoulder, dag_armRoot, JointProcess.IKSolverType.SingleChain)[0]; MDagPath[] shoulderResult = BindIKControl(dag_shoulder, dag_armRoot, JointProcess.IKSolverType.SingleChain); MDagPath[] armResult = BindIKControl(dag_armRoot, dag_wrist, JointProcess.IKSolverType.RotatePlane); MDagPath dag_ctl_shoulder = shoulderResult[1], dag_ctl_arm = armResult[1], dag_ctl_pole = armResult[2]; BasicFunc.SetTransformParent(dag_ctl_arm.fullPathName, dag_ctl_shoulder.fullPathName); BasicFunc.SetTransformParent(dag_ctl_pole.fullPathName, dag_ctl_shoulder.fullPathName); BasicFunc.AddConstraint(dag_ctl_arm.fullPathName, dag_wrist.fullPathName, ConstantValue.ConstraintType.Orient); //MFnTransform trans_ctl_shoulder = new MFnTransform(dag_ctl_shoulder); //MFnTransform trans_ctl_arm = new MFnTransform(dag_ctl_arm); //MFnTransform trans_ctl_pole = new MFnTransform(dag_ctl_pole); //BasicFunc.SetTransformParent(trans_ctl_arm, trans_ctl_shoulder); //BasicFunc.SetTransformParent(trans_ctl_pole, trans_ctl_shoulder); }
public static void ExtractFacesIntoOneObject(MSelectionList faceList) { if (faceList == null) { return; } MDagPath originDag = new MDagPath(); faceList.getDagPath(0, originDag); Selector selector = new Selector(); selector.SetFromSelection(faceList); MDagPath newDag = BasicFunc.Duplicate(originDag); MSelectionList targetPartInDuplicated = selector.RestoreSelectionOnDag(newDag, true); //new MFnTransform(newDag).setTranslation(new MVector(0, 2, 0), MSpace.Space.kWorld); //BasicFunc.Select(faceList); BasicFunc.DoDelete(faceList); MDagPath dag_targetPartInD = new MDagPath(); MSelectionList invertSelection = BasicFunc.InvertSelect(targetPartInDuplicated, newDag, ConstantValue.PolySelectType.Facet); BasicFunc.DoDelete(invertSelection); }
public virtual bool ProcessReceive(byte[] buffer, int offset, int count) //接收异步事件返回的数据,用于对数据进行缓存和分包 { var receiveBuffer = MAsyncSocketUserToken.ReceiveBuffer; receiveBuffer.WriteBuffer(buffer, offset, count); if (receiveBuffer.DataCount >= BasicFunc.MinPacketLength) { var packetLength = 0; if (!BasicFunc.CheckPacket(buffer, ref packetLength)) { return(true); } if (receiveBuffer.DataCount >= packetLength) //收到的数据达到包长度 { var result = ProcessPacket(receiveBuffer.Buffer, 0, packetLength); if (result) { receiveBuffer.Clear(packetLength); //从缓存中清理 } return(result); } else { return(true); } } else { return(true); } }
//登录 public bool DoLogin() { string userName = ""; string password = ""; //UserName/Password if (m_incomingDataParser.GetValue(ProtocolKey.UserName, ref userName) & m_incomingDataParser.GetValue(ProtocolKey.Password, ref password)) { if (password.Equals(BasicFunc.MD5String("admin"), StringComparison.CurrentCultureIgnoreCase)) { m_outgoingDataAssembler.AddSuccess(); m_userName = userName; m_logined = true; Program.Logger.InfoFormat("{0} login success", userName); Console.WriteLine("{0} login success", userName); //todo:lyj } else { m_outgoingDataAssembler.AddFailure(ProtocolCode.UserOrPasswordError, ""); Program.Logger.ErrorFormat("{0} login failure,password error", userName); Console.WriteLine("{0} login failure,password error", userName); //todo:lyj } } else { m_outgoingDataAssembler.AddFailure(ProtocolCode.ParameterError, ""); } return(DoSendResult()); }
public static bool BindReverseFootRPIK(MDagPath legRootDagPath, MDagPath ankleDagPath, MDagPath middleDagPath, MDagPath endDagPath) { //ypa //create reverseBones MFnIkJoint[] rbs = AddReverseFootBone(ankleDagPath, middleDagPath, endDagPath); //ankle, heel, side, front, middleF, middleB, toe, ankleIn if (rbs == null) { return(false); } Debug.Log(rbs[7].fullPathName); MDagPath ikDagPath = BindIKControl(legRootDagPath, ankleDagPath, JointProcess.IKSolverType.RotatePlane, rbs[7].dagPath)[0]; MGlobal.executeCommandStringResult("orientConstraint -mo " + rbs[4].fullPathName + " " + middleDagPath.fullPathName); MGlobal.executeCommandStringResult("orientConstraint -mo " + rbs[5].fullPathName + " " + ankleDagPath.fullPathName); //set limit test BasicFunc.SetRotationLimit(rbs[1], -ConstantValue.Radian15, 0, 0, ConstantValue.Radian30, 0, 0); BasicFunc.SetRotationLimit(rbs[2], 0, 0, -ConstantValue.Radian45, 0, 0, ConstantValue.Radian45); BasicFunc.SetRotationLimit(rbs[3], -ConstantValue.Radian45, -ConstantValue.Radian45, 0, ConstantValue.Radian45, ConstantValue.Radian45, 0); BasicFunc.SetRotationLimit(rbs[4], -ConstantValue.Radian45, 0, 0, 0, 0, 0); BasicFunc.SetRotationLimit(rbs[5], 0, 0, 0, ConstantValue.Radian45, 0, 0); return(true); }
public static bool BindBlendShapeCtl(MFnBlendShapeDeformer bs, MDagPath ctlDagPath = null) { //MFnDependencyNode ctlNode = new MFnDependencyNode(ctlDagPath.node); if (bs == null) { Debug.Log("null blendShape"); return(false); } //Debug.Log("here i am"); if (ctlDagPath == null) { ctlDagPath = BasicFunc.CreateCTL_Crystal("ctl_bs_" + bs.name); } MFnDependencyNode ctlNode = new MFnDependencyNode(ctlDagPath.node); MPlug weightPlug = bs.findPlug(ConstantValue.plugName_blendShapeWeight); int count = (int)weightPlug.numElements; //Debug.Log("target count:" + count); MDGModifier dGModifier = new MDGModifier(); for (int i = 0; i < count; i++) { //Debug.Log("process:" + i); MPlug singleWeightPlug = weightPlug.elementByLogicalIndex((uint)i); string weightName = singleWeightPlug.name.Split('.').Last(); MPlug ctlAttrPlug = AddFloatAttr(ctlDagPath, weightName); dGModifier.connect(ctlAttrPlug, singleWeightPlug); } dGModifier.doIt(); return(true); }
public static List <CommandData> GetCommandDatas() { List <CommandData> cmdList = new List <CommandData>(); cmdList.Add(new CommandData("绑定", "手指")); cmdList.Add(new CommandData("绑定", cmdStr, "bindFinger", "绑定手指控制器", () => { BindFinger(BasicFunc.GetSelectedDagPath(0), "test", false); })); cmdList.Add(new CommandData("绑定", "旋转平面")); cmdList.Add(new CommandData("绑定", cmdStr, "rpik", "绑定旋转平面IK控制器", () => { BindIKControl(); })); cmdList.Add(new CommandData("绑定", cmdStr, "rpikPole", "生成极向量控制器", () => { AddRPIKPole(); })); cmdList.Add(new CommandData("绑定", "JIO")); cmdList.Add(new CommandData("绑定", cmdStr, "reverseFootBones", "生成反向脚部控制骨", () => { AddReverseFootBone(); })); cmdList.Add(new CommandData("绑定", cmdStr, "reverseFootRPIK", "绑定反向脚控制器", () => { BindReverseFootRPIK(); })); cmdList.Add(new CommandData("绑定", "上半身")); cmdList.Add(new CommandData("绑定", cmdStr, "bindBreast", "绑定上半身与腰部", () => { BindBodySplineIK(); })); cmdList.Add(new CommandData("绑定", cmdStr, "bindShoulder", "绑定人类肩膀-手臂", () => { BindShoulder(); })); cmdList.Add(new CommandData("绑定", "面部")); cmdList.Add(new CommandData("绑定", cmdStr, "bindTongue", "绑定花京院型舌头", () => { //BindReverseFootRPIK(); })); cmdList.Add(new CommandData("绑定", cmdStr, "bindSight", "绑定平视控制器", () => { //BindReverseFootRPIK(); })); cmdList.Add(new CommandData("绑定", cmdStr, "createJointCTLs", "根据骨骼位置创建控制器阵列", () => { AddBonesCTL(); })); return(cmdList); }
private void RenameSelected(object sender, RoutedEventArgs e) { BasicFunc.IterateSelectedObjects((mo) => { MFnDependencyNode node = new MFnDependencyNode(mo); node.setName(GetNewName(node.name)); }); }
public static bool ProjectPlug(MPlug from, MPlug to, float fromMin, float fromMax, float toMin, float toMax) { MFnDependencyNode remapValueNode = BasicFunc.CreateRemapValueNode(fromMin, fromMax, toMin, toMax); MDGModifier dGModifier = new MDGModifier(); dGModifier.connect(from, remapValueNode.findPlug(ConstantValue.plugName_remapValueInput)); dGModifier.connect(remapValueNode.findPlug(ConstantValue.plugName_remapValueOutput), to); dGModifier.doIt(); return(true); }
bool IExtensionPlugin.InitializePlugin() { totalMenuName = GetMayaWindowName(); cds.AddRange(BasicFunc.GetCommandDatas()); cds.AddRange(BindHumanBody.GetCommandDatas()); cds.AddRange(DynamicConverter.GetCommandDatas()); cds.AddRange(JointProcess.GetCommandDatas()); cds.AddRange(MaterialManage.GetCommandDatas()); cds.AddRange(BindAttr.GetCommandDatas()); cds.AddRange(Selector.GetCommandDatas()); cds.AddRange(BindSwitch.GetCommandDatas()); cds.AddRange(MeshTool.GetCommandDatas()); foreach (CommandData cd in cds) { AddOneCommand(cd); } //int paramInt = (int)MPCMap.MPCType.Test; //AddMenuItem("Test", totalMenuName, "InazumaCommand", paramInt); //string subMenuName_bodyBind = AddSubMenu(totalMenuName, "Body Bind", true); //string subMenuName_create = AddSubMenu(totalMenuName, "Create", true); //paramInt = (int)MPCMap.MPCType.AddRPIK; //AddMenuItem("add rpik", subMenuName_bodyBind, "InazumaCommand", paramInt); //paramInt = (int)MPCMap.MPCType.AddRPIKPole; //AddMenuItem("add rpik pole", subMenuName_create, "InazumaCommand", paramInt); //paramInt = (int)MPCMap.MPCType.CreateCTL_CrysTal; //AddMenuItem("create cystal ctl", subMenuName_create, "InazumaCommand", paramInt); //paramInt = (int)MPCMap.MPCType.AddChildCtl; //AddMenuItem("add child ctl", subMenuName_create, "InazumaCommand", paramInt); //paramInt = (int)MPCMap.MPCType.AddParentCtl; //AddMenuItem("add parent ctl", subMenuName_create, "InazumaCommand", paramInt); //paramInt = (int)MPCMap.MPCType.AddReverseFootBones; //AddMenuItem("add reverse foot bones", subMenuName_create, "InazumaCommand", paramInt); //paramInt = (int)MPCMap.MPCType.BindReverseFootRPIK; //AddMenuItem("Bind Reverse Foot RPIK", subMenuName_bodyBind, "InazumaCommand", paramInt); //paramInt = (int)MPCMap.MPCType.BindFinger_CTL_L; //AddMenuItem("Bind Finger using CTL L", subMenuName_bodyBind, "InazumaCommand", paramInt); //paramInt = (int)MPCMap.MPCType.CreateJointsCurve; //AddMenuItem("Create Joints Curve", subMenuName_create, "InazumaCommand", paramInt); //paramInt = (int)MPCMap.MPCType.MakeHairJointsChain; //AddMenuItem("Make Hair Joints To Chain", subMenuName_bodyBind, "InazumaCommand", paramInt); Debug.Log("-回港了-"); return(true); }
private void RenameHierachy(object sender, RoutedEventArgs e) { BasicFunc.IterateSelectedDags((dag) => { List <MDagPath> dags = BasicFunc.GetHierachyAll(dag); foreach (MDagPath d in dags) { MFnDependencyNode node = new MFnDependencyNode(d.node); node.setName(GetNewName(node.name)); } }); }
public static void BindBodySplineIK(MSelectionList jointList = null) { if (jointList == null) { jointList = BasicFunc.GetSelectedList(); } //check if all of selected objects are joint int count = (int)jointList.length; if (count < 2) { return; } MDagPath dag_breastJoint = new MDagPath(), dag_hipJoint = new MDagPath(); for (int i = 0; i < count; i++) { MDagPath jtDagPath = new MDagPath(); jointList.getDagPath((uint)i, jtDagPath); if (jtDagPath != null) { if (!jtDagPath.hasFn(MFn.Type.kJoint)) { return; } } else { return; } } jointList.getDagPath((uint)(count - 1), dag_breastJoint); jointList.getDagPath(0, dag_hipJoint); MFnIkJoint breastJoint = new MFnIkJoint(dag_breastJoint); MFnIkJoint hipJoint = new MFnIkJoint(dag_hipJoint); MDagPath dag_curve = JointProcess.CreateJointsCurve(jointList); MDagPath dag_jtctl_breast = JointProcess.CreateJoint(breastJoint, "jtctl_breast"); MDagPath dag_jtctl_hip = JointProcess.CreateJoint(hipJoint, "jtctl_hip"); MSelectionList bindSelectionList = new MSelectionList(); bindSelectionList.add(dag_curve); bindSelectionList.add(dag_jtctl_breast); bindSelectionList.add(dag_jtctl_hip); BasicFunc.Select(bindSelectionList); MGlobal.executeCommand("SmoothBindSkin"); string ikName = JointProcess.AddIKHandle(dag_hipJoint, dag_breastJoint, JointProcess.IKSolverType.Spline, dag_curve.fullPathName)[0]; MDagPath dag_ik = BasicFunc.GetDagPathByName(ikName); BasicFunc.ConnectAttr(dag_jtctl_breast.fullPathName + ".rotate.rotateY", dag_ik.fullPathName + ".twist", true, true); }
public static void BindNCloth(MSelectionList selecteList = null) { if (selecteList == null) { selecteList = BasicFunc.GetSelectedList(); } int count = (int)selecteList.length; if (count <= 1) { //Debug.Log("ncloth control switch target: select [ctl,ncloth0,ncloth1...]"); return; } else { //Debug.Log("ncloth control switch target count:" + count); } MDagPath ctlDag = new MDagPath(); selecteList.getDagPath(0, ctlDag); selecteList.remove(0); MFnDependencyNode dn_ctl = new MFnDependencyNode(ctlDag.node); BasicFunc.IterateSelectedDags((dag) => { //Debug.Log("ncloth control set for:"+dag.fullPathName); MPlug ctlNewAttrPlug = BindAttr.AddBoolAttr(dn_ctl, "Dynamic_" + dag.partialPathName, true, "", false); dag.extendToShape(); MFnDependencyNode dn_nCloth = new MFnDependencyNode(dag.node); MPlug plug_isDynamic = dn_nCloth.findPlug(ConstantValue.plugName_nCloth_isDynamic); MPlug plug_currentTime = dn_nCloth.findPlug(ConstantValue.plugName_nCloth_currentTime); if (plug_isDynamic != null && plug_currentTime != null) { MPlugArray inputArr_currentTime = new MPlugArray(); plug_currentTime.connectedTo(inputArr_currentTime, true, false); MFnDependencyNode dn_time = new MFnDependencyNode(inputArr_currentTime[0].node); BindAttr.ProjectPlug(plug_isDynamic, dn_time.findPlug(ConstantValue.plugName_nClothTime_nodeState), 0, 1, (int)ConstantValue.TimeNodeState.Stuck, (int)ConstantValue.TimeNodeState.Normal); } BasicFunc.ConnectPlug(ctlNewAttrPlug, plug_isDynamic); }, MFn.Type.kNCloth, selecteList); //List<string> nclothNameList = new List<string>(); //foreach (MDagPath dag in nclothList.DagPaths()) //{ // nclothNameList.Add() //} }
public static void ExecuteBasicFuntion(string Name, string[] Arguments, string ObjectName, WebObject.Base CurrentObject) { MethodInfo[] BasicFunctionsList = typeof(BasicFunctions).GetMethods(); foreach (MethodInfo BasicFunc in BasicFunctionsList) { if (BasicFunc.Name == Name) { object[] BasicArguments = new object[3]; BasicArguments[0] = ObjectName; BasicArguments[1] = Arguments; BasicArguments[2] = CurrentObject; BasicFunc.Invoke(BasicFunc, BasicArguments); } } }
public static void BindEyes(MSelectionList jointList = null) { if (jointList == null) { jointList = BasicFunc.GetSelectedList(); } List <MDagPath> jointDags = new List <MDagPath>(); for (int i = 0; i < jointList.length; i++) { MDagPath dag_joint = new MDagPath(); jointList.getDagPath((uint)i, dag_joint); jointDags.Add(dag_joint); } }
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); }
public static MDagPath[] BindIKControl(MDagPath rootDagPath, MDagPath endDagPath, JointProcess.IKSolverType iKSolverType = JointProcess.IKSolverType.RotatePlane, MDagPath ctlDagPath = null) { MFnTransform endTrans = new MFnTransform(endDagPath); MDagPath middleDagPath = MDagPath.getAPathTo(endTrans.parent(0)); if (ctlDagPath == null) { ctlDagPath = BasicFunc.AddChildCircle(endDagPath); BasicFunc.UnparentTransform(ctlDagPath); BasicFunc.FreezeTransform(new MFnTransform(ctlDagPath)); } //string resultStr = MGlobal.executeCommandStringResult("ikHandle -sj " + rootObject.fullPathName() + " -ee " + endObject.fullPathName() + " -sol ikRPsolver -n ik_" + rootObject.partialPathName() + "_" + endObject.partialPathName(),true); //string resultStr = MGlobal.executePythonCommandStringResult("cmds.ikHandle(sj='" + rootDagPath.fullPathName + "',ee='" + endDagPath.fullPathName + "',sol='ikRPsolver',n='ik_" + rootDagPath.partialPathName + "_" + endDagPath.partialPathName + "')"); //[u'ik_joint1_joint4', u'effector1'] string[] resultArr = JointProcess.AddIKHandle(rootDagPath, endDagPath, iKSolverType, ctlDagPath.fullPathName); MGlobal.executeCommandStringResult("pointConstraint " + ctlDagPath.fullPathName + " " + resultArr[0]); if (iKSolverType == JointProcess.IKSolverType.RotatePlane) { MDagPath locDagPath = AddRPIKPole(middleDagPath); if (locDagPath != null) { BasicFunc.FreezeTransform(new MFnTransform(locDagPath)); //begin to add constriant BasicFunc.AddConstraint(locDagPath.fullPathName, resultArr[0], ConstantValue.ConstraintType.PoleVector); //string poleConstraintResult = MGlobal.executeCommandStringResult("poleVectorConstraint " + locDagPath.fullPathName + " " + resultArr[0]); //Debug.Log(poleConstraintResult); return(new MDagPath[3] { BasicFunc.GetDagPathByName(resultArr[0]), ctlDagPath, locDagPath }); } } return(new MDagPath[2] { BasicFunc.GetDagPathByName(resultArr[0]), ctlDagPath }); }
public static List <CommandData> GetCommandDatas() { List <CommandData> cmdList = new List <CommandData>(); //cmdList.Add(new CommandData("网格", "材质")); cmdList.Add(new CommandData("网格", cmdStr, "printEdges", "打印所有边", () => { BasicFunc.IterateSelectedDags((dag) => { dag.extendToShape(); MFnMesh mesh = new MFnMesh(dag); CombineOverLappingEdge(mesh, 0.01f); }, MFn.Type.kMesh); })); cmdList.Add(new CommandData("网格", cmdStr, "realExtract", "老实地提取", () => { ExtractFacesIntoOneObject(BasicFunc.GetSelectedList()); })); return(cmdList); }
private void ConvertToUDIM(object sender, RoutedEventArgs e) { MaterialManage.CombineToUDIM(BasicFunc.GetSelectedObjectList(), text_prename.Text, text_newFolder.Text, int.Parse(text_uCount.Text)); }
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); }
public static MFnIkJoint[] AddReverseFootBone(MDagPath rootDagPath, MDagPath middleDagPath, MDagPath endDagPath) { //啊啊 //*reverseBones = new MDagPath[8]; MFnIkJoint[] result = new MFnIkJoint[8]; MFnIkJoint rootJoint = new MFnIkJoint(); MVector rootPos = new MFnTransform(rootDagPath).getTranslation(MSpace.Space.kWorld); MVector middlePos = new MFnTransform(middleDagPath).getTranslation(MSpace.Space.kWorld); MVector endPos = new MFnTransform(endDagPath).getTranslation(MSpace.Space.kWorld); //Debug.Log("root:" + BasicFunc.ToCMDSParamStr(rootPos) + " middle:" + BasicFunc.ToCMDSParamStr(middlePos) + " end:" + BasicFunc.ToCMDSParamStr(endPos)); MObject jt_ankle_Object = rootJoint.create(); result[0] = new MFnIkJoint(MDagPath.getAPathTo(jt_ankle_Object)); result[0].setTranslation(rootPos, MSpace.Space.kWorld); MObject jt_heel_Object = rootJoint.create(jt_ankle_Object); result[1] = new MFnIkJoint(MDagPath.getAPathTo(jt_heel_Object)); result[1].setTranslation(new MVector(rootPos.x, endPos.y, rootPos.z), MSpace.Space.kWorld); MObject jt_side_Object = rootJoint.create(jt_heel_Object); result[2] = new MFnIkJoint(MDagPath.getAPathTo(jt_side_Object)); MVector footDirect = endPos - middlePos; MVector middleGround = new MVector(middlePos.x, endPos.y, middlePos.z); MVector offset = BasicFunc.Cross(footDirect, new MVector(0, 0.6, 0)); offset *= Math.Sign(BasicFunc.Dot(middleGround, offset)); //float sideFactor = (float)(0.6 * (middlePos - endPos).length / Math.Abs(middlePos.z)); result[2].setTranslation(middleGround + offset, MSpace.Space.kWorld); MObject jt_front_Object = rootJoint.create(jt_side_Object); result[3] = new MFnIkJoint(MDagPath.getAPathTo(jt_front_Object)); result[3].setTranslation(endPos, MSpace.Space.kWorld); MObject jt_middleF_Object = rootJoint.create(jt_front_Object); result[4] = new MFnIkJoint(MDagPath.getAPathTo(jt_middleF_Object)); result[4].setTranslation(middlePos, MSpace.Space.kWorld); MObject jt_middleB_Object = rootJoint.create(jt_front_Object); result[5] = new MFnIkJoint(MDagPath.getAPathTo(jt_middleB_Object)); result[5].setTranslation(middlePos, MSpace.Space.kWorld); MObject jt_toe_Object = rootJoint.create(jt_middleF_Object); result[6] = new MFnIkJoint(MDagPath.getAPathTo(jt_toe_Object)); result[6].setTranslation(endPos, MSpace.Space.kWorld); MObject jt_ankleIn_Object = rootJoint.create(jt_middleB_Object); result[7] = new MFnIkJoint(MDagPath.getAPathTo(jt_ankleIn_Object)); result[7].setTranslation(rootPos, MSpace.Space.kWorld); Debug.Log("create joints ok"); return(result); }
public static bool BindFinger(MDagPath rootJointDagPath, MDagPath middleJointDagPath, MDagPath finalJointDagPath, string fingerTag, bool useIK = false) { JointProcess.SetJointLimit(rootJointDagPath, JointProcess.JointType.FingerRoot); JointProcess.SetJointLimit(middleJointDagPath, JointProcess.JointType.FingerMiddle); JointProcess.SetJointLimit(finalJointDagPath, JointProcess.JointType.FingerMiddle); if (useIK) { } else { MDagPath ctlDagPath = BasicFunc.AddParentCircle(rootJointDagPath, true); MFnDependencyNode remapNode_root = BasicFunc.CreateRemapValueNode(-2, 3, 60, -90); MFnDependencyNode remapNode_rootSide = BasicFunc.CreateRemapValueNode(-1, 1, 30, -30); MFnDependencyNode remapNode_middle = BasicFunc.CreateRemapValueNode(-1, 3, 30, -90); MFnDependencyNode remapNode_final = BasicFunc.CreateRemapValueNode(-1, 3, 30, -90); //MFnDependencyNode** ptr_remapNode_root = &remapNode_root, //string remapValueNodeName_root = BasicFunc.CreateRemapValueNode(-2, 3, 60, -90, ptr_remapNode_root); //string remapValueNodeName_rootSide = BasicFunc.CreateRemapValueNode(-1, 1, 30, -30, ptr_remapNode_rootSide); //string remapValueNodeName_middle = BasicFunc.CreateRemapValueNode(-1, 3, 30, -90, ptr_remapNode_middle); //string remapValueNodeName_final = BasicFunc.CreateRemapValueNode(-1, 3, 30, -90, ptr_remapNode_final); string ctlName = ctlDagPath.fullPathName; MFnDependencyNode dn_ctl = new MFnDependencyNode(ctlDagPath.node); MFnDependencyNode dn_root = new MFnDependencyNode(rootJointDagPath.node); MFnDependencyNode dn_middle = new MFnDependencyNode(middleJointDagPath.node); MFnDependencyNode dn_final = new MFnDependencyNode(finalJointDagPath.node); /*MPlug plug_ctlTy = dn_ctl.findPlug("translateY"); * Debug.Log("plug name:" + plug_ctlTy.partialName() + " fullname:" + plug_ctlTy.name());*/ //MStatus status; //MPlug plug_remapNode_root_input = remapNode_root.findPlug("inputValue", &status); //if (status == MStatus::kSuccess) //{ // Debug.Log("success 634634"); // //Debug.Log("plug name:" + plug_remapNode_root_input.partialName() + " fullname:" + plug_remapNode_root_input.name()); //} //else //{ // Debug.Log("failed a23234234"); //} MDGModifier dgModifier = new MDGModifier(); dgModifier.doIt(); dgModifier.connect(dn_ctl.findPlug("translateY"), remapNode_root.findPlug("inputValue")); dgModifier.connect(remapNode_root.findPlug("outValue"), dn_root.findPlug("rotateZ")); dgModifier.connect(dn_ctl.findPlug("translateZ"), remapNode_rootSide.findPlug("inputValue")); dgModifier.connect(remapNode_rootSide.findPlug("outValue"), dn_root.findPlug("rotateY")); dgModifier.connect(dn_ctl.findPlug("translateX"), remapNode_middle.findPlug("inputValue")); dgModifier.connect(remapNode_middle.findPlug("outValue"), dn_middle.findPlug("rotateZ")); dgModifier.connect(dn_ctl.findPlug("translateX"), remapNode_final.findPlug("inputValue")); dgModifier.connect(remapNode_final.findPlug("outValue"), dn_final.findPlug("rotateZ")); dgModifier.doIt(); BasicFunc.SetTranslateLimit(new MFnTransform(ctlDagPath), -1, -2, -1, 3, 3, 1); } return(true); }
private void RenameSingle(object sender, RoutedEventArgs e) { MFnDependencyNode node = new MFnDependencyNode(BasicFunc.GetSelectedObject(0)); node.setName(GetNewName(node.name)); }
private void ConvertToRSMats(object sender, RoutedEventArgs e) { MaterialManage.ConvertToRSMaterial(new MFnDependencyNode(BasicFunc.GetSelectedObject(0)), (bool)bto_deleteOriginMats.IsChecked); }
private void LoadJoints(object sender, RoutedEventArgs e) { joints.Clear(); //stackPanels.Clear(); grid_jointSliders.Children.Clear(); sliders.Clear(); BasicFunc.IterateSelectedDags((dag) => { joints.Add(new MFnIkJoint(dag)); }, MFn.Type.kJoint); //<StackPanel Orientation="Horizontal"> // <Button Style="{StaticResource NormalButton}" Width="80" Height="40" Click="LoadJoints">Joint 0</Button> // <Slider Style="{StaticResource NormalSlider}" Name="test"/> //</StackPanel> MVector lastJointWorldPos = joints[joints.Count - 1].getTranslation(MSpace.Space.kWorld); MVector firstJointWorldPos = joints[0].getTranslation(MSpace.Space.kWorld); double totalLength = (lastJointWorldPos - firstJointWorldPos).length; for (int i = 0; i < joints.Count; i++) { StackPanel panel = new StackPanel { Orientation = Orientation.Horizontal }; Button btn = new Button { Style = this.FindResource("NormalButton") as Style, Width = 80, Height = 40, Name = "jointBtn_" + i, Content = joints[i].absoluteName }; int index = i;//local variable is important btn.Click += new RoutedEventHandler((obj, ea) => { //choose BasicFunc.Select(joints[index].dagPath); }); panel.Children.Add(btn); if (i != 0 && i != joints.Count - 1) { MVector jointWorldPos = joints[i].getTranslation(MSpace.Space.kWorld); Slider newSlider = new Slider { Style = this.FindResource("NormalSlider") as Style, Name = "jointSlider_" + i }; newSlider.Value = (jointWorldPos - firstJointWorldPos).length / totalLength; //newSlider.ValueChanged += new RoutedPropertyChangedEventHandler<double>((obj, rpce) => //{ // .NewValue //}); panel.Children.Add(newSlider); sliders.Add(newSlider); } else { sliders.Add(null); } grid_jointSliders.Children.Add(panel); } //newSlider. }