Beispiel #1
0
        public static void DeleteUnusedShadingNode(MSelectionList list)
        {
            if (list == null)
            {
                Debug.Log("list null");
                return;
            }
            List <MFnDependencyNode> deleteList = new List <MFnDependencyNode>();

            for (int i = 0; i < list.length; i++)
            {
                MObject mo = new MObject();
                list.getDependNode((uint)i, mo);
                if (mo.hasFn(MFn.Type.kShadingEngine))
                {
                    MFnDependencyNode sgNode = new MFnDependencyNode(mo);
                    MPlug             plug_dagSetMemebers = sgNode.findPlug(ConstantValue.plugName_dagSetMembers);
                    Debug.Log("numelements:" + plug_dagSetMemebers.numElements);
                    if (plug_dagSetMemebers.numElements == 0)
                    {
                        deleteList.Add(sgNode);
                    }
                }
                //Debug.Log(sgNode.name);
            }
            BasicFunc.DeleteObjects(deleteList);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        public static MDagPath CreateLoopCircleByPos(List <MVector> posList, bool reOrder = true, bool closedArc = true, string ctlName = "loopCircle_0")
        {
            List <MVector> vectors = new List <MVector>(posList);

            if (vectors.Count < 2)
            {
                return(default(MDagPath));
            }
            if (reOrder)
            {
                int count = vectors.Count;
                //List<float> radians = new List<float>();
                Dictionary <MVector, float> radianDic = new Dictionary <MVector, float>();
                for (int i = 0; i < count; i++)
                {
                    radianDic.Add(vectors[i], BasicFunc.CalPosRadian(vectors[i]));
                }
                vectors.Sort((a, b) =>
                {
                    if (radianDic[a] > radianDic[b])
                    {
                        return(1);
                    }
                    else
                    {
                        return(-1);
                    }
                });
            }
            if (closedArc)
            {
                vectors.Add(vectors[0]);
            }
            return(BasicFunc.CreateCurve(vectors.ToArray(), ctlName, 1, closedArc ? MFnNurbsCurve.Form.kClosed : MFnNurbsCurve.Form.kOpen));
        }
Beispiel #4
0
        public static List <CommandData> GetCommandDatas()
        {
            List <CommandData> cmdList = new List <CommandData>();

            cmdList.Add(new CommandData(null, cmdStr, "test", "test", () =>
            {
                BasicFunc.PrintObjects(BasicFunc.GetSelectedList());
            }));
            cmdList.Add(new CommandData(null, cmdStr, "testSelectComp", "选择组件", () =>
            {
                BasicFunc.Select(BasicFunc.GetSelectedList(), true);
            }));
            cmdList.Add(new CommandData("基本操作", cmdStr, "childCircle", "增加子层级圆环", () =>
            {
                AddChildCircle(GetSelectedDagPath(0));
            }));
            cmdList.Add(new CommandData("基本操作", cmdStr, "parentCircle", "增加同层级圆环", () =>
            {
                AddParentCircle(GetSelectedDagPath(0), true);
            }));
            cmdList.Add(new CommandData("基本操作", cmdStr, "crystal", "创建八面体控制器", () =>
            {
                BasicFunc.CreateCTL_Crystal("ctl_sample");
            }));
            cmdList.Add(new CommandData("基本操作", cmdStr, "cthulhu", "创建偏方三八面体", () =>
            {
                BasicFunc.CreateCTL_Crystal("ctl_sample");
            }));
            return(cmdList);
        }
        public static MDagPath CreateJointsCurve(MSelectionList jointDagPathList)
        {
            int    count     = (int)jointDagPathList.length;
            string curveName = "curve_";

            MVector[] vectors = new MVector[count];
            for (int i = 0; i < count; i++)
            {
                MDagPath dagPath = new MDagPath();
                jointDagPathList.getDagPath((uint)i, dagPath);
                if (i == 0)
                {
                    curveName += dagPath.partialPathName + "_";
                }
                else if (i == count - 1)
                {
                    curveName += dagPath.partialPathName;
                }
                MFnTransform ptTrans = new MFnTransform(dagPath);
                vectors[i] = ptTrans.getTranslation(MSpace.Space.kWorld);
                //MGlobal.displayInfo(BasicFunc::ToCMDSParamStr(vectors[i]));
            }
            MDagPath curveDagPath = BasicFunc.CreateCurve(vectors, curveName);

            //MGlobal.displayInfo("create Finish");


            return(curveDagPath);
        }
Beispiel #6
0
        public static void ConvertHairSelection(HairSelectionType hairSelectionType, MDagPath dagPath = null)
        {
            //MGlobal.executeCommand("convertHairSelection \"current\"");
            if (dagPath != null)
            {
                BasicFunc.Select(dagPath);
            }
            switch (hairSelectionType)
            {
            case HairSelectionType.Follicles:
            {
                MGlobal.executeCommand("convertHairSelection \"follicles\"");
                break;
            }

            case HairSelectionType.HairSystem:
            {
                MGlobal.executeCommand("convertHairSelection \"hairSystems\"");
                break;
            }

            case HairSelectionType.OutputCurves:
            {
                MGlobal.executeCommand("convertHairSelection \"current\"");
                break;
            }

            case HairSelectionType.StartCurves:
            {
                MGlobal.executeCommand("convertHairSelection \"startCurves\"");
                break;
            }
            }
        }
Beispiel #7
0
        public static MDagPath AddDynamicChainControl(ref MDagPath hairSystem, MSelectionList jointChains = null, ConstantValue.HairPointLockType pointLock = ConstantValue.HairPointLockType.Base)
        {
            //get bones
            if (jointChains == null)
            {
                jointChains = BasicFunc.GetSelectedList();
            }
            if (jointChains.length == 0)
            {
                return(null);
            }

            MDagPath dagPath_startJoint = new MDagPath(), dagPath_endJoint = new MDagPath();

            if (jointChains.length == 1)
            {
                BasicFunc.Select(jointChains);
                jointChains.getDagPath((uint)0, dagPath_startJoint);
                MGlobal.executeCommand("select -hierarchy " + dagPath_startJoint.fullPathName);
                jointChains = BasicFunc.GetSelectedList(MFn.Type.kJoint);
            }


            jointChains.getDagPath(0, dagPath_startJoint);
            jointChains.getDagPath(jointChains.length - 1, dagPath_endJoint);

            MDagPath startCurveDagPath = JointProcess.CreateJointsCurve(jointChains);
            MDagPath outCurveDagPath   = CurveToHair(ref hairSystem, startCurveDagPath, pointLock);

            JointProcess.AddIKHandle(dagPath_startJoint, dagPath_endJoint, JointProcess.IKSolverType.Spline, outCurveDagPath.fullPathName);

            BasicFunc.SetTransformParent(BasicFunc.GetParent(startCurveDagPath), BasicFunc.GetParent(dagPath_startJoint));

            return(outCurveDagPath);
        }
Beispiel #8
0
        public MSelectionList RestoreSelectionOnList(MSelectionList targetList = null, bool selectResult = false)
        {
            if (targetList == null || targetList.length == 0)
            {
                targetList = BasicFunc.GetSelectedList();
            }

            MSelectionList resultSelection = new MSelectionList();

            for (int i = 0; i < targetList.length; i++)
            {
                if (i >= selectedIndicesList.Count)
                {
                    break;
                }
                MDagPath dag = new MDagPath();
                targetList.getDagPath((uint)i, dag);
                MFnSingleIndexedComponent sic = new MFnSingleIndexedComponent();
                MObject components            = sic.create(MFn.Type.kMeshPolygonComponent);
                sic.addElements(new MIntArray(selectedIndicesList[i]));
                resultSelection.add(dag, components);
                //resultSelection.add(dag);
            }
            if (selectResult)
            {
                BasicFunc.Select(resultSelection);
            }
            return(resultSelection);
        }
Beispiel #9
0
        public static void RemoveUnusedTextures(MSelectionList list)
        {
            if (list == null)
            {
                Debug.Log("list null");
                return;
            }
            List <MObject> deleteList = new List <MObject>();

            for (int i = 0; i < list.length; i++)
            {
                MObject mo = new MObject();
                list.getDependNode((uint)i, mo);
                MFnDependencyNode imageNode     = new MFnDependencyNode(mo);
                MPlug             texOutputPlug = imageNode.findPlug(ConstantValue.plugName_fileTexOutputColor);
                MPlugArray        destPlugs     = new MPlugArray();
                texOutputPlug.destinations(destPlugs);
                if (destPlugs.Count == 0)
                {
                    deleteList.Add(mo);
                    Debug.Log("remove no use:" + imageNode.absoluteName);
                }
                else
                {
                    Debug.Log("still used:" + imageNode.absoluteName);
                    for (int j = 0; j < destPlugs.length; j++)
                    {
                        Debug.Log(" by:" + destPlugs[0].partialName(true));
                    }
                }
            }
            BasicFunc.DeleteObjects(deleteList);
        }
Beispiel #10
0
        public static void CreateRelativeCurve(MSelectionList selected = null, ConstantValue.SampleType st = ConstantValue.SampleType.ObjectTrans, bool reOrder = true, bool closedArc = true, string ctlName = null)
        {
            if (selected == null)
            {
                selected = BasicFunc.GetSelectedList();
            }
            List <MVector> positions = new List <MVector>();

            switch (st)
            {
            case ConstantValue.SampleType.Vert:
            {
                MItSelectionList it_selectionList = new MItSelectionList(selected);
                MVector          totalWeight      = MVector.zero;
                for (; !it_selectionList.isDone; it_selectionList.next())
                {
                    MObject  component = new MObject();
                    MDagPath item      = new MDagPath();
                    it_selectionList.getDagPath(item, component);
                    MItMeshVertex it_verts = new MItMeshVertex(item, component);
                    for (; !it_verts.isDone; it_verts.next())
                    {
                        //Debug.Log(it_verts.index().ToString());
                        MPoint  point = it_verts.position(MSpace.Space.kWorld);
                        MVector pos   = new MVector(point.x, point.y, point.z);
                        //BasicFunc.CreateLocator(pos, "vert_" + it_verts.index());
                        positions.Add(pos);
                        totalWeight += pos;
                    }
                }
                break;
            }

            case ConstantValue.SampleType.Edge:
            {
                break;
            }

            case ConstantValue.SampleType.Poly:
            {
                break;
            }

            case ConstantValue.SampleType.ObjectTrans:
            {
                foreach (MDagPath dag in selected.DagPaths())
                {
                    MFnTransform trans = new MFnTransform(dag);
                    positions.Add(trans.getTranslation(MSpace.Space.kWorld));
                }
                break;
            }
            }
            if (ctlName == null)
            {
                ctlName = "samplerCurve_00";
            }
            CreateLoopCircleByPos(positions, reOrder, closedArc, ctlName);
        }
        public static MVector GetLinearPosByWeight(MVector middleWorldPos, MVector parentWorldPos, MVector childWorldPos)
        {
            float   length0     = (float)(middleWorldPos - parentWorldPos).length;
            float   length1     = (float)(middleWorldPos - childWorldPos).length;
            MVector posByWeight = BasicFunc.Lerp(parentWorldPos, childWorldPos, length0 / (length0 + length1));

            return(posByWeight);
        }
 public static void MoveSkinJointsTool(MDagPath dag = null)
 {
     if (dag != null)
     {
         BasicFunc.Select(dag);
     }
     MGlobal.executeCommand("MoveSkinJointsTool");
 }
Beispiel #13
0
        /// <summary>
        /// well, this action is truely dangerous
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public static bool CombineMaterials(MSelectionList list, bool deleteRepeated = true)
        {
            if (!BasicFunc.CheckSelectionList(list, 2))
            {
                Debug.Log("please choose at least 2 materials");
                return(false);
            }

            string                firstMatName  = "";
            List <MObject>        deleteList    = new List <MObject>();
            List <MSelectionList> waitForAssign = new List <MSelectionList>();

            MDGModifier dGModifier = new MDGModifier();

            for (uint i = 0; i < list.length; i++)
            {
                //Debug.Log(i + " mat test");
                MObject matObject = new MObject();
                list.getDependNode(i, matObject);
                MFnDependencyNode dnode = new MFnDependencyNode(matObject);
                if (i == 0)
                {
                    firstMatName = dnode.absoluteName;
                    continue;
                }
                else
                {
                    deleteList.Add(matObject);
                }
                //Debug.Log(i + " node:" + dnode.absoluteName);
                if (matObject.hasFn(MFn.Type.kLambert) || matObject.hasFn(MFn.Type.kBlinn) || matObject.hasFn(MFn.Type.kPhong))
                {
                    //Debug.Log("has mat fn");
                    //MMaterial mat = new MMaterial(matObject);
                    //MColor color = new MColor();
                    //mat.getDiffuse(color);
                    //Debug.Log("mat:" + dnode.absoluteName + " ,color:" + BasicFunc.MToString(color));
                    SelectObjectsWithMat(dnode);
                    //Debug.Log("finish select");


                    //waitForAssign.Add(BasicFunc.GetSelectedList());
                    AssignMat(firstMatName);
                    //Debug.Log("finish assign");
                    BasicFunc.DeleteByCMD(dnode.absoluteName);
                    //Debug.Log("finish delete");
                }
                else
                {
                    Debug.Log("no mat fn");
                }
            }

            dGModifier.doIt();

            //MGlobal.executeCommandOnIdle("hyperShade -objects " + matNode.absoluteName);
            return(true);
        }
Beispiel #14
0
        public static void Select(MSelectionList list, bool selectInComponentMode = false)
        {
            MGlobal.setActiveSelectionList(list);

            if (selectInComponentMode)
            {
                Debug.Log("select in component mode");
                List <MSelectionList> facesListToAdd = new List <MSelectionList>();

                MItSelectionList it_selectionList = new MItSelectionList(list);
                Debug.Log("has components:" + it_selectionList.hasComponents);

                for (; !it_selectionList.isDone; it_selectionList.next())
                {
                    MObject  component = new MObject();
                    MDagPath item      = new MDagPath();
                    it_selectionList.getDagPath(item, component);

                    //Debug.Log(item.fullPathName + " has components:" + it_selectionList.hasComponents);
                    //List<int> selectedIndcies = new List<int>();
                    //MItMeshPolygon it_poly = new MItMeshPolygon(item, component);
                    if (!it_selectionList.hasComponents)
                    {
                        //Debug.Log("没有组件被选择,怀疑是一整个物体:" + item.fullPathName);
                        BasicFunc.SelectComponent(item.fullPathName, ConstantValue.PolySelectType.Facet, true);
                        facesListToAdd.Add(BasicFunc.GetSelectedList());
                    }
                    //else
                    //{
                    //    Debug.Log("有组件被选择:" + it_poly.count());
                    //}
                }
                if (facesListToAdd.Count > 0)
                {
                    MGlobal.setActiveSelectionList(list);
                    for (int i = 0; i < facesListToAdd.Count; i++)
                    {
                        MGlobal.setActiveSelectionList(facesListToAdd[i], MGlobal.ListAdjustment.kAddToList);
                    }
                }
            }
            //bool hasDag = false;

            //if (hasDag)
            //{
            //    Debug.Log("has dag length:" + list.length);
            //    foreach (MDagPath dag in list.DagPaths())
            //    {
            //        Debug.Log(dag.fullPathName);
            //    }
            //    MGlobal.setActiveSelectionList(list);
            //}
            //else
            //{
            //    Debug.Log("no dag but length:" + list.length);
            //    MGlobal.setActiveSelectionList(list);
            //}
        }
        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 string[] AddIKHandle(MDagPath startJointDagPath, MDagPath endJointDagPath, IKSolverType solverType = IKSolverType.RotatePlane, string curveName = "")
        {
            //string typeStr = "";
            string resultStr = "";

            CmdStrConstructor csc = new CmdStrConstructor("ikHandle", CmdStrConstructor.CmdType.Python);

            csc.UpdateParm("sj", startJointDagPath.fullPathName);
            csc.UpdateParm("ee", endJointDagPath.fullPathName);

            string ikMainName = startJointDagPath.partialPathName + "_" + endJointDagPath.partialPathName;

            switch (solverType)
            {
            case IKSolverType.SingleChain:
            {
                csc.UpdateParm("sol", "ikSCsolver");
                csc.UpdateParm("n", "ik_" + ikMainName);
                string excuteStr = csc.ToString();
                resultStr = MGlobal.executePythonCommandStringResult(excuteStr);
                //typeStr = "ikSCsolver";
                //resultStr = MGlobal.executePythonCommandStringResult("cmds.ikHandle(sj='" + startJointDagPath.fullPathName + "',ee='" + endJointDagPath.fullPathName + "',sol='" + typeStr + "',n='ik_" + ikMainName + "')");
                break;
            }

            case IKSolverType.RotatePlane:
            {
                csc.UpdateParm("sol", "ikRPsolver");
                csc.UpdateParm("n", "ik_" + ikMainName);
                string excuteStr = csc.ToString();
                resultStr = MGlobal.executePythonCommandStringResult(excuteStr);
                //typeStr = "ikRPsolver";
                //resultStr = MGlobal.executePythonCommandStringResult("cmds.ikHandle(sj='" + startJointDagPath.fullPathName + "',ee='" + endJointDagPath.fullPathName + "',sol='" + typeStr + "',n='ik_" + ikMainName + "')");
                break;
            }

            case IKSolverType.Spline:
            {
                csc.UpdateParm("sol", "ikSplineSolver");
                csc.UpdateParm("n", "ik_" + ikMainName);
                csc.UpdateParm("ccv", curveName == null || curveName.Length == 0);
                csc.UpdateParm("c", curveName);
                csc.UpdateParm("pcv", false);
                string excuteStr = csc.ToString();
                resultStr = MGlobal.executePythonCommandStringResult(excuteStr);
                //resultStr = MGlobal.executePythonCommandStringResult("cmds.ikHandle(sj='" + startJointDagPath.fullPathName + "',ee='" + endJointDagPath.fullPathName + "',sol='" + typeStr + "',c='" + curveName + "',n='ik_" + ikMainName + "')",true);
                break;
            }
            }
            //[u'ik_joint1_joint4', u'effector1']
            string[] resultArr = BasicFunc.SplitPythonResultStr(resultStr);

            return(resultArr);
        }
Beispiel #17
0
        public static string RenameTexFile(MFnDependencyNode imageNode, string newPartialName, string newFolder = null, bool relinkImgNode = false, bool deleteOrigin = false, bool overwrite = false)
        {
            MPlug  plug_fileTexPath = imageNode.findPlug(ConstantValue.plugName_fileTexPath);
            string originFullPath   = plug_fileTexPath.asString();
            string newFullPath      = BasicFunc.RenameFile(originFullPath, newPartialName, newFolder, deleteOrigin, overwrite);

            if (relinkImgNode)
            {
                plug_fileTexPath.setString(newFullPath);
            }
            return(newFullPath);
        }
Beispiel #18
0
        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 List <CommandData> GetCommandDatas()
        {
            List <CommandData> cmdList = new List <CommandData>();

            cmdList.Add(new CommandData("骨骼", cmdStr, "add", "沿骨骼生成曲线", () =>
            {
                CreateJointsCurve(BasicFunc.GetSelectedList());
            }));
            cmdList.Add(new CommandData("骨骼", cmdStr, "clearRotation", "清除层级下骨骼旋转", () =>
            {
                ClearHierachyJointsRotation();
            }));
            cmdList.Add(new CommandData("骨骼/优雅极向量", cmdStr, "beautifulPole_x", "极向量清除X", () =>
            {
                BeautifulPole(null, true, false, false);
            }));
            cmdList.Add(new CommandData("骨骼/优雅极向量", cmdStr, "beautifulPole_y", "极向量清除Y", () =>
            {
                BeautifulPole(null, false, true, false);
            }));
            cmdList.Add(new CommandData("骨骼/优雅极向量", cmdStr, "beautifulPole_z", "极向量清除Z", () =>
            {
                BeautifulPole(null, false, false, true);
            }));
            cmdList.Add(new CommandData("骨骼/优雅极向量", cmdStr, "beautifulPole_xy", "极向量清除XY", () =>
            {
                BeautifulPole(null, true, true, false);
            }));
            cmdList.Add(new CommandData("骨骼/优雅极向量", cmdStr, "beautifulPole_xz", "极向量清除XZ", () =>
            {
                BeautifulPole(null, true, false);
            }));
            cmdList.Add(new CommandData("骨骼/优雅极向量", cmdStr, "beautifulPole_yz", "极向量清除YZ", () =>
            {
                BeautifulPole(null, false);
            }));
            cmdList.Add(new CommandData("骨骼/优雅极向量", cmdStr, "beautifulPole_xyz", "极向量清除XYZ", () =>
            {
                BeautifulPole(null);
            }));
            cmdList.Add(new CommandData("骨骼", cmdStr, "manyBeautifulPole", "为很多漂亮的极向量铺路", () =>
            {
                BasicFunc.IterateSelectedDags((dag) => { BeautifulPole(dag, true); });
            }));
            cmdList.Add(new CommandData("骨骼", "过渡骨"));
            cmdList.Add(new CommandData("骨骼", cmdStr, "lerpJoints", "过渡骨编辑器", () =>
            {
                JointProcessWindow jpw = new JointProcessWindow();
                jpw.Topmost            = true;
                jpw.Show();
            }));
            return(cmdList);
        }
Beispiel #20
0
        public void CreateButtonWindow()
        {
            BasicWindow bw = new BasicWindow("Selector");

            Action[] actions = new Action[3];
            actions[0] = () =>
            {
                for (int i = 0; i < selectedIndicesList.Count; i++)
                {
                    string msg = "";
                    for (int j = 0; j < selectedIndicesList[i].Length; j++)
                    {
                        msg += selectedIndicesList[i][j];
                        if (j != 0)
                        {
                            msg += ",";
                        }
                    }
                    Debug.Log("Selected " + i + ":" + msg);
                }
            };
            actions[1] = () =>
            {
                SetFromSelection();
            };
            actions[2] = () =>
            {
                RestoreSelectionOnList(null, true);
            };

            Action[] actions2 = new Action[2]
            {
                () =>
                {
                    //Delete For One Group
                    BasicFunc.DoDelete(RestoreSelectionOnList(), true);
                },
                () =>
                {
                    //Delete For Multi Group
                    DoForMultiSelection((list) => { BasicFunc.DoDelete(list); });
                }
            };

            bw.AddButtons(actions, new string[3] {
                "Print", "Refresh Select", "Restore Selection"
            });
            bw.AddButtons(actions2, new string[2] {
                "Delete Topo", "Delete Topo For Multi"
            });

            bw.Show();
        }
Beispiel #21
0
 static void MoveUV(float uValue, float vValue, string matName = null, bool splitUVBlockBeforeMove = true)
 {
     if (matName != null)
     {
         Debug.Log("matName:" + matName);
         SelectObjectsWithMat(matName, true);
     }
     if (splitUVBlockBeforeMove)
     {
         SplitUVBlock(BasicFunc.GetSelectedList(), true);
     }
     MGlobal.executeCommand(string.Format("polyEditUV -u {0} -v {1}", uValue, vValue), true);
 }
Beispiel #22
0
        public static void AddDynamicConstraint(MSelectionList list, ConstantValue.DynamicConstraintType dynamicConstraintType = ConstantValue.DynamicConstraintType.PointToPoint, ConstantValue.DynamicConstraintMethod method = ConstantValue.DynamicConstraintMethod.Weld)
        {
            if (list == null)
            {
                list = BasicFunc.GetSelectedList();
            }
            BasicFunc.Select(list);
            string typeStr = ConstantValue.Param_DynamicConstraintType(dynamicConstraintType);
            string cmdStr  = "createNConstraint " + typeStr + " 0";
            string dynamicConstraintShapeName = MGlobal.executeCommandStringResult(cmdStr);

            BasicFunc.SetAttr(dynamicConstraintShapeName, ConstantValue.plugName_dynamicConstraintMethod, "" + (int)method);
        }
Beispiel #23
0
        public static MDagPath CurveToHair(ref MDagPath hairSystemDagPath, MDagPath curveDagPath = null, ConstantValue.HairPointLockType pointLock = ConstantValue.HairPointLockType.Base)
        {
            if (curveDagPath == null)
            {
                curveDagPath = BasicFunc.GetSelectedDagPath(0);
            }
            bool           hairSystemReady = !hairSystemDagPath.node.isNull;
            MSelectionList targetList      = new MSelectionList();

            targetList.add(curveDagPath);
            if (hairSystemReady)
            {
                Debug.Log("hair system ready");
                targetList.add(hairSystemDagPath);
            }
            else
            {
                Debug.Log("hair system need to be created!");
            }
            BasicFunc.Select(targetList);


            string cmdStr    = "cmds.MakeCurvesDynamic(0,0,0,1,0)";
            string resultStr = MGlobal.executePythonCommandStringResult(cmdStr);

            MDagPath result = new MDagPath();

            //Debug.Log(curveDagPath.fullPathName);
            MFnTransform curveTrans = new MFnTransform(curveDagPath);

            if (curveTrans.parentCount > 0)
            {
                MDagPath follicleDagPath = MDagPath.getAPathTo(curveTrans.parent(0));
                MGlobal.executeCommand(string.Format("setAttr {0}.pointLock {1}", follicleDagPath.fullPathName, (int)pointLock));
                if (follicleDagPath.hasFn(MFn.Type.kFollicle))
                {
                    Debug.Log("follicle exist!");
                    ConvertHairSelection(HairSelectionType.OutputCurves, follicleDagPath);
                    result = BasicFunc.GetSelectedDagPath(0);
                    new MFnDependencyNode(result.node).setName("dy_" + curveDagPath.partialPathName);
                    if (!hairSystemReady)
                    {
                        ConvertHairSelection(HairSelectionType.HairSystem);
                        hairSystemDagPath = BasicFunc.GetSelectedDagPath(0);
                        hairSystemReady   = true;
                    }
                }
            }

            return(result);
        }
Beispiel #24
0
        public static MFnDependencyNode CreateShadingNode(ShadingNodeType snt, string nodeType)
        {
            //Debug.Log("try create shadingNode:" + snt + " :" + nodeType);
            CmdStrConstructor csc = new CmdStrConstructor("shadingNode");

            switch (snt)
            {
            case ShadingNodeType.Texture:
            {
                csc.UpdateToggle("at", true);
                break;
            }

            case ShadingNodeType.Utility:
            {
                csc.UpdateToggle("au", true);
                break;
            }

            case ShadingNodeType.Shader:
            {
                csc.UpdateToggle("as", true);
                break;
            }

            case ShadingNodeType.Light:
            {
                csc.UpdateToggle("al", true);
                break;
            }

            case ShadingNodeType.PostProcess:
            {
                csc.UpdateToggle("app", true);
                break;
            }

            case ShadingNodeType.Rendering:
            {
                csc.UpdateToggle("ar", true);
                break;
            }
            }
            csc.UpdateFinalAppend(nodeType);
            string cmdStr = csc.ToString();
            //Debug.Log("command:" + cmdStr);
            string nodeName = MGlobal.executeCommandStringResult(cmdStr, true);

            //Debug.Log("create node result:" + nodeName);
            return(new MFnDependencyNode(BasicFunc.GetObjectByName(nodeName)));
        }
Beispiel #25
0
        public static void CombineDagsWithSameMat(MSelectionList list)
        {
            if (list == null)
            {
                Debug.Log("list null");
                return;
            }
            List <List <string> >   matClusterList = new List <List <string> >();
            List <List <MDagPath> > dagClusterList = new List <List <MDagPath> >();

            //Dictionary<List<string>, List<MDagPath>> matDic = new Dictionary<List<MFnDependencyNode>, List<MDagPath>>();
            foreach (MDagPath dag in list.DagPaths())
            {
                ShapeData sd    = GetMaterialsOfDag(dag);
                bool      exist = false;
                for (int i = 0; i < matClusterList.Count; i++)
                {
                    if (BasicFunc.IsSame(sd.sgList, matClusterList[i]))
                    {
                        exist = true;
                        dagClusterList[i].Add(dag);
                    }
                }
                if (!exist)
                {
                    matClusterList.Add(sd.sgList);
                    List <MDagPath> newDagList = new List <MDagPath>();
                    newDagList.Add(dag);
                    dagClusterList.Add(newDagList);
                }
            }
            for (int i = 0; i < matClusterList.Count; i++)
            {
                string matStr = "combined_";
                for (int j = 0; j < matClusterList[i].Count; j++)
                {
                    matStr += matClusterList[i][j] + "_";
                }
                Debug.Log(matStr);
                matStr.Replace(':', '_');
                Debug.Log("after deal:" + matStr);
                MeshTool.CombineMeshesUsingMEL(dagClusterList[i], matStr);

                //matStr += ":";
                //for (int j = 0; j < dagClusterList[i].Count; j++)
                //{
                //    matStr += "," + dagClusterList[i][j].fullPathName;
                //}
                //Debug.Log(matStr);
            }
        }
        private static List <MFnIkJoint> GetSelectedJoints(MSelectionList selectedList = null)
        {
            if (selectedList == null)
            {
                selectedList = BasicFunc.GetSelectedList();
            }
            List <MFnIkJoint> joints = new List <MFnIkJoint>();

            BasicFunc.IterateSelectedDags((dag) =>
            {
                joints.Add(new MFnIkJoint(dag));
            }, MFn.Type.kJoint, selectedList);
            return(joints);
        }
Beispiel #27
0
        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);
        }
Beispiel #28
0
        static bool SelectObjectsWithMat(string matName, bool selectInComponentMode = false)
        {
            if (matName == null || matName.Length == 0)
            {
                Debug.Log("matName null or empty");
                return(false);
            }
            MGlobal.executeCommand("hyperShade -objects " + matName);


            if (selectInComponentMode)
            {
                Debug.Log("select in component mode");
                MSelectionList list = BasicFunc.GetSelectedList();
                BasicFunc.Select(list, true);
                //List<MSelectionList> facesListToAdd = new List<MSelectionList>();

                //if (list.length > 0)
                //{


                //    for (int i = (int)list.length - 1; i >= 0; i--)
                //    {
                //        MObject mo = new MObject();
                //        list.getDependNode((uint)i, mo);
                //        if (mo.apiType == MFn.Type.kMesh)
                //        {
                //            //component,no change
                //        }
                //        else if (mo.apiType == MFn.Type.kTransform)
                //        {
                //            //full object,select the faces
                //            BasicFunc.SelectComponent(MDagPath.getAPathTo(mo).fullPathName, ConstantValue.PolySelectType.Facet, true);
                //            facesListToAdd.Add(BasicFunc.GetSelectedList());
                //        }


                //    }

                //    MGlobal.setActiveSelectionList(list);
                //    for (int i = 0; i < facesListToAdd.Count; i++)
                //    {
                //        MGlobal.setActiveSelectionList(facesListToAdd[i], MGlobal.ListAdjustment.kAddToList);
                //    }
                //}
            }

            return(true);
        }
Beispiel #29
0
 static void SplitUVBlock(MSelectionList faceSelection, bool recoverSelection = true)
 {
     if (recoverSelection)
     {
         MSelectionList originList = BasicFunc.GetSelectedList();
         BasicFunc.Select(faceSelection);
         MGlobal.executeCommand(ConstantValue.command_ConvertSelectionToEdgePerimeter);
         MGlobal.executeCommand(ConstantValue.command_CutUVs);
         BasicFunc.Select(originList);
     }
     else
     {
         BasicFunc.Select(faceSelection);
         MGlobal.executeCommand(ConstantValue.command_ConvertSelectionToEdgePerimeter);
         MGlobal.executeCommand(ConstantValue.command_CutUVs);
     }
 }
 public static void ClearHierachyJointsRotation(MSelectionList selectionList = null)
 {
     if (selectionList == null || selectionList.length == 0)
     {
         selectionList = BasicFunc.GetSelectedList();
     }
     foreach (MDagPath dag in selectionList.DagPaths())
     {
         List <MFnTransform> transList = BasicFunc.GetHierachyAllTrans(dag, MFn.Type.kJoint);
         foreach (MFnTransform trans in transList)
         {
             //Debug.Log("trans:" + trans.fullPathName);
             trans.setRotation(new MEulerRotation(0, 0, 0));
             MEulerRotation result = new MEulerRotation();
             trans.getRotation(result);
             //Debug.LogEuler(result, "value");
         }
     }
 }