Beispiel #1
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 #2
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 #3
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);
        }
Beispiel #4
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);
        }
Beispiel #5
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 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 #7
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 #8
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);
 }
        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 #10
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 #11
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");
         }
     }
 }
Beispiel #13
0
        public static List <MDagPath> AddDynamicChainControlPerChain(MSelectionList rootJointsList = null)
        {
            if (rootJointsList == null)
            {
                rootJointsList = BasicFunc.GetSelectedList();
            }
            MDagPath        oneJoint   = new MDagPath();
            MDagPath        hairSystem = new MDagPath();
            List <MDagPath> result     = new List <MDagPath>();

            for (int i = 0; i < rootJointsList.length; i++)
            {
                rootJointsList.getDagPath((uint)i, oneJoint);
                MSelectionList tempList = new MSelectionList();
                tempList.add(oneJoint);
                AddDynamicChainControl(ref hairSystem, tempList);
            }
            return(result);
        }
Beispiel #14
0
        public void DoForMultiSelection(Action <MSelectionList> dealMethod, MSelectionList targetList = null)
        {
            if (targetList == null || targetList.length == 0)
            {
                targetList = BasicFunc.GetSelectedList();
            }

            int groupCount = selectedIndicesList.Count;

            for (int i = 0; i *groupCount < targetList.length; i++)
            {
                MSelectionList groupList = new MSelectionList();
                for (int j = 0; j < groupCount; j++)
                {
                    int      index = i * groupCount + j;
                    MDagPath dag   = new MDagPath();
                    targetList.getDagPath((uint)index, dag);
                    groupList.add(dag);
                }
                dealMethod(RestoreSelectionOnList(groupList));
            }
        }
Beispiel #15
0
        public static List <CommandData> GetCommandDatas()
        {
            List <CommandData> cmdList = new List <CommandData>();


            cmdList.Add(new CommandData("材质", "图片"));
            cmdList.Add(new CommandData("材质", cmdStr, "matsWithSameTex", "选择同图片材质", () =>
            {
                BasicFunc.Select(GetMaterialsWithTex(BasicFunc.GetSelectedObject(0)));
            }));
            cmdList.Add(new CommandData("材质", cmdStr, "combineMats", "合并选中材质", () =>
            {
                CombineMaterials(BasicFunc.GetSelectedList());
            }));
            cmdList.Add(new CommandData("材质", cmdStr, "confirmPlace2dTexture", "贴图place2dTexture修复", () =>
            {
                RenameMaterials(BasicFunc.GetSelectedList());
            }));
            cmdList.Add(new CommandData("材质", cmdStr, "renameMaterials", "重命名材质节点(根据图片名)", () =>
            {
                RenameMaterials(BasicFunc.GetSelectedList());
            }));
            cmdList.Add(new CommandData("材质", cmdStr, "combineMatSharing", "合并相同贴图材质(选中的每个图片)", () =>
            {
                BasicFunc.IterateSelectedObjects((imgObject) =>
                {
                    CombineMaterials(GetMaterialsWithTex(imgObject));
                }, MFn.Type.kFileTexture);
            }));
            cmdList.Add(new CommandData("材质", cmdStr, "deleteUnusedMats", "删除无用材质", () =>
            {
                DeleteUnusedMats(BasicFunc.GetSelectedList());
            }));
            cmdList.Add(new CommandData("材质", cmdStr, "deleteUnusedSGs", "删除无用着色组", () =>
            {
                DeleteUnusedShadingNode(BasicFunc.GetSelectedList());
            }));

            cmdList.Add(new CommandData("材质", "材质"));
            cmdList.Add(new CommandData("材质", cmdStr, "combineTextures", "合并相同路径图片", () =>
            {
                CombineSameTextures(BasicFunc.GetSelectedList());
            }));
            cmdList.Add(new CommandData("材质", cmdStr, "renameTextures", "重命名图片节点", () =>
            {
                RenameTextures(BasicFunc.GetSelectedList());
            }));
            cmdList.Add(new CommandData("材质", cmdStr, "removeUnused", "删除无用图片", () =>
            {
                RemoveUnusedTextures(BasicFunc.GetSelectedList());
            }));

            cmdList.Add(new CommandData("材质", "物体"));
            cmdList.Add(new CommandData("材质", cmdStr, "combineSameMatObjects", "合并材质完全相同的物体", () =>
            {
                CombineDagsWithSameMat(BasicFunc.GetSelectedList());
            }));

            cmdList.Add(new CommandData("材质", "整合"));
            cmdList.Add(new CommandData("材质", cmdStr, "selectMatComponent", "选择属于此材质的所有组件", () =>
            {
                SelectObjectsWithMat(new MFnDependencyNode(BasicFunc.GetSelectedObject(0)), true);
            }));

            //cmdList.Add(new CommandData("材质", cmdStr, "moveMatUV", "移动此材质UV", () =>
            //{
            //    CombineDagsWithSameMat(BasicFunc.GetSelectedList());
            //}));
            cmdList.Add(new CommandData("材质", cmdStr, "convertToLayered", "转换为LayeredTextures", () =>
            {
                CreateLayeredTextureNode(BasicFunc.GetSelectedObjectList());
            }));
            //cmdList.Add(new CommandData("材质", cmdStr, "conbineToUDIM1", "合并为UDIM-1", () =>
            //{
            //    CombineToUDIM(BasicFunc.GetSelectedObjectList(), "udim","UDIM",1);
            //}));
            //cmdList.Add(new CommandData("材质", cmdStr, "conbineToUDIM2", "合并为UDIM-2", () =>
            //{
            //    CombineToUDIM(BasicFunc.GetSelectedObjectList(), "udim", "UDIM", 2);
            //}));
            //cmdList.Add(new CommandData("材质", cmdStr, "conbineToUDIM3", "合并为UDIM-3", () =>
            //{
            //    CombineToUDIM(BasicFunc.GetSelectedObjectList(), "udim", "UDIM", 3);
            //}));
            //cmdList.Add(new CommandData("材质", cmdStr, "conbineToUDIM4", "合并为UDIM-4", () =>
            //{
            //    CombineToUDIM(BasicFunc.GetSelectedObjectList(), "udim", "UDIM", 4);
            //}));
            //cmdList.Add(new CommandData("材质", cmdStr, "conbineToUDIM5", "合并为UDIM-5", () =>
            //{
            //    CombineToUDIM(BasicFunc.GetSelectedObjectList(), "udim", "UDIM", 5);
            //}));
            cmdList.Add(new CommandData("材质", cmdStr, "udimEditor", "UDIM编辑器", () =>
            {
                UI.MaterialManageWindow window = new UI.MaterialManageWindow();
                window.Show();
            }));
            cmdList.Add(new CommandData("材质", "RS"));
            cmdList.Add(new CommandData("材质", cmdStr, "convertMatToRS", "材质转为RS-Architecture", () =>
            {
                ConvertToRSMaterial(new MFnDependencyNode(BasicFunc.GetSelectedObject(0)), false);
            }));

            cmdList.Add(new CommandData("材质", cmdStr, "tempConvert_delete", "临时-批量改贴图路径文件夹", () =>
            {
                Debug.Log("没做好编辑器所以就不调用了");
                //ChangeTexturesPrefix(BasicFunc.GetSelectedList(), @"D:\testTextures");
            }));


            return(cmdList);
        }
Beispiel #16
0
        public int[] SetFromSelection(MSelectionList selected = null)
        {
            selectedIndicesList.Clear();
            if (selected == null)
            {
                //
                selected = BasicFunc.GetSelectedList();
            }

            //List<MVector> positions = new List<MVector>();
            MItSelectionList it_selectionList = new MItSelectionList(selected);

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

                List <int>   selectedIndcies = new List <int>();
                Action <int> xx = (indice) => { selectedIndcies.Add(indice); };

                switch (selectType)
                {
                case SelectType.Edge:
                {
                    MItMeshEdge it_edges = new MItMeshEdge(item, component);
                    for (; !it_edges.isDone; it_edges.next())
                    {
                        selectedIndcies.Add(it_edges.index(0));
                        selectedIndcies.Add(it_edges.index(1));
                    }
                    break;
                }

                case SelectType.Face:
                {
                    MItMeshPolygon it_poly = new MItMeshPolygon(item, component);

                    for (; !it_poly.isDone; it_poly.next())
                    {
                        selectedIndcies.Add((int)it_poly.index());
                    }

                    break;
                }

                case SelectType.Vert:
                {
                    MItMeshVertex it_verts = new MItMeshVertex(item, component);

                    for (; !it_verts.isDone; it_verts.next())
                    {
                        selectedIndcies.Add(it_verts.index());
                    }

                    break;
                }
                }

                selectedIndicesList.Add(selectedIndcies.ToArray());
            }
            int[] resultCount = new int[selectedIndicesList.Count];
            for (int i = 0; i < resultCount.Length; i++)
            {
                resultCount[i] = selectedIndicesList[i].Length;
            }
            return(resultCount);
        }
Beispiel #17
0
        public static void CreateSpiderNetCurves(MSelectionList selected = null, bool convertToHair = true, bool addConstraint = true, bool bindJoints = true)
        {
            if (selected == null)
            {
                selected = BasicFunc.GetSelectedList();
            }
            List <MDagPath>        verticalCurves = new List <MDagPath>(), horizontalCurves = new List <MDagPath>();
            List <List <MVector> > colList = new List <List <MVector> >();

            List <MDagPath[]> jointPairToBind = new List <MDagPath[]>();

            int rowCount = 0;

            foreach (MDagPath dag in selected.DagPaths())
            {
                List <MFnTransform> transList  = BasicFunc.GetHierachyChainTrans(dag);
                List <MVector>      vectorList = new List <MVector>();
                if (transList.Count > rowCount)
                {
                    rowCount = transList.Count;
                }
                for (int i = 0; i < transList.Count; i++)
                {
                    vectorList.Add(transList[i].getTranslation(MSpace.Space.kWorld));
                }
                if (bindJoints)
                {
                    jointPairToBind.Add(new MDagPath[2] {
                        transList[0].dagPath, transList[transList.Count - 1].dagPath
                    });
                }
                colList.Add(vectorList);
                verticalCurves.Add(CreateLoopCircleByPos(vectorList, false, false, string.Format("netCurve_column_{0:d4}", (colList.Count - 1))));
            }
            List <List <MVector> > rowList = new List <List <MVector> >();

            for (int i = 0; i < rowCount; i++)
            {
                List <MVector> rowCircle = new List <MVector>();
                for (int j = 0; j < colList.Count; j++)
                {
                    rowCircle.Add(colList[j][i]);
                }
                rowList.Add(rowCircle);
                horizontalCurves.Add(CreateLoopCircleByPos(rowCircle, false, true, string.Format("netCurve_row_{0:d4}", (rowCircle.Count - 1))));
            }
            if (convertToHair)
            {
                MDagPath       hairSystem         = new MDagPath();
                MSelectionList listToDynamicCurve = new MSelectionList();
                Debug.Log("vertical to dynamic count:" + verticalCurves.Count);
                for (int i = 0; i < verticalCurves.Count; i++)
                {
                    listToDynamicCurve.add(verticalCurves[i]);
                }
                MDagPath[] verticalOutputCurves = CurvesToHairs(ref hairSystem, listToDynamicCurve, ConstantValue.HairPointLockType.Base);
                Debug.Log("vertical dynamic result count:" + verticalOutputCurves.Length);
                BasicFunc.RenameDagList(verticalOutputCurves, "netDyCurve_vertical_{0:d2}");
                listToDynamicCurve.clear();
                Debug.Log("horizontal to dynamic count:" + horizontalCurves.Count);
                for (int i = 0; i < horizontalCurves.Count; i++)
                {
                    listToDynamicCurve.add(horizontalCurves[i]);
                }
                MDagPath[] horizontalOutputCurves = CurvesToHairs(ref hairSystem, listToDynamicCurve, ConstantValue.HairPointLockType.None);
                Debug.Log("horizontal dynamic result count:" + horizontalOutputCurves.Length);
                BasicFunc.RenameDagList(horizontalOutputCurves, "netDyCurve_horizontal_{0:d2}");
                if (bindJoints)
                {
                    for (int i = 0; i < verticalOutputCurves.Length; i++)
                    {
                        JointProcess.AddIKHandle(jointPairToBind[i][0], jointPairToBind[i][1], JointProcess.IKSolverType.Spline, verticalOutputCurves[i].fullPathName);
                    }
                }
                if (addConstraint)
                {
                    MSelectionList outputCurveList = new MSelectionList();
                    for (int i = 0; i < verticalOutputCurves.Length; i++)
                    {
                        outputCurveList.add(verticalOutputCurves[i]);
                    }
                    for (int i = 0; i < horizontalOutputCurves.Length; i++)
                    {
                        outputCurveList.add(horizontalOutputCurves[i]);
                    }
                    AddDynamicConstraint(outputCurveList);
                }
            }
            else if (bindJoints)
            {
                for (int i = 0; i < jointPairToBind.Count; i++)
                {
                    JointProcess.AddIKHandle(jointPairToBind[i][0], jointPairToBind[i][1], JointProcess.IKSolverType.Spline, verticalCurves[i].fullPathName);
                }
            }
        }
Beispiel #18
0
        /// <summary>
        /// return Dynamic Output Curve
        /// </summary>
        /// <param name="hairSystemDagPath">exist hairsystem or container of created hairsystem</param>
        /// <param name="curveList"></param>
        /// <param name="pointLock">0-none, 1-base, 2-end,3-both</param>
        /// <returns></returns>
        public static MDagPath[] CurvesToHairs(ref MDagPath hairSystemDagPath, MSelectionList curveList = null, ConstantValue.HairPointLockType pointLock = ConstantValue.HairPointLockType.Base)
        {
            if (curveList == null)
            {
                curveList = BasicFunc.GetSelectedList();
            }

            bool hairSystemReady = false;

            if (!hairSystemDagPath.node.isNull)
            {
                //Debug.Log("hairSystem node is not null:" + hairSystemDagPath.fullPathName);
                curveList.add(hairSystemDagPath);
                hairSystemReady = true;
            }
            else
            {
                //Debug.Log("hairsystem node is null");
            }
            MGlobal.setActiveSelectionList(curveList);
            string cmdStr    = "cmds.MakeCurvesDynamic(0,0,0,1,0)";
            string resultStr = MGlobal.executePythonCommandStringResult(cmdStr);

            if (hairSystemReady)
            {
                //Debug.Log("remove hairSystem Selection");
                curveList.remove(curveList.length - 1);
            }
            List <MDagPath> results = new List <MDagPath>();

            for (int i = 0; i < curveList.length; i++)
            {
                MDagPath curveDagPath = new MDagPath();
                curveList.getDagPath((uint)i, curveDagPath);

                //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);
                        MDagPath result = BasicFunc.GetSelectedDagPath(0);
                        new MFnDependencyNode(result.node).setName("dy_" + curveDagPath.partialPathName);
                        results.Add(result);
                        if (!hairSystemReady)
                        {
                            ConvertHairSelection(HairSelectionType.HairSystem);
                            hairSystemDagPath = BasicFunc.GetSelectedDagPath(0);
                            //Debug.Log("assign hairSystem:" + hairSystemDagPath.fullPathName);
                            hairSystemReady = true;
                        }
                    }
                }
            }


            //error
            return(results.ToArray());
        }