예제 #1
0
        internal void GetNewGeom()
        {
            // VMDataBridge.DataBridge.Instance.UnregisterCallback(GUID.ToString());
            if (firstRun)
            {
                firstRun = false;
            }
            else
            {
                if (SelectedItems != null)
                {
                    foreach (var itm in SelectedItems.Values)
                    {
                        itm.Dispose();
                    }
                }
            }

            MSelectionList selectionList = new MSelectionList();

            MGlobal.getActiveSelectionList(selectionList, true);

            if (selectionList.isEmpty)
            {
                if (selectionList.isEmpty)
                {
                    SelectedItems = null;
                    OnNodeModified(true);
                    return;
                }
            }

            var TransObjectList = selectionList.DagPaths(MFn.Type.kTransform).ToList();
            var DagObjectList   = selectionList.DagPaths(MFn.Type.kMesh).ToList();

            SelectedItems       = new Dictionary <string, DMMesh>(DagObjectList.Count);
            m_SelectedItemNames = new List <string>(DagObjectList.Count);

            foreach (var dag in TransObjectList)
            {
                if (dag.hasFn(MFn.Type.kMesh))
                {
                    var itm = new DMMesh(dag, space);
                    itm.Renamed += Itm_Renamed;
                    itm.Deleted += MObjOnDeleted;
                    SelectedItems.Add(itm.dagName, itm);
                    m_SelectedItemNames.Add(itm.dagName);
                    // ct++;
                }
                else
                {
                    MGlobal.displayWarning($"Selected item is not a kMesh, it is a {dag.apiType}");
                }
            }

            m_SelectedItemNamesString = ConvertStringListToString(m_SelectedItemNames);

            OnNodeModified(true);
        }
예제 #2
0
        public static MSelectionList DuplicateDags(MSelectionList list)
        {
            if (list == null)
            {
                return(null);
            }
            MSelectionList originSelect = GetSelectedList();

            CmdStrConstructor cc = new CmdStrConstructor("duplicate");

            cc.UpdateToggle("rr", true);
            List <string> targets = new List <string>();

            foreach (MDagPath dag in list.DagPaths())
            {
                targets.Add(dag.fullPathName);
            }
            cc.UpdateTargets(targets);
            MGlobal.executeCommand(cc.ToString());

            //string resultName = MGlobal.executeCommandStringResult("duplicate -rr");
            MSelectionList newList = GetSelectedList();

            Select(originSelect);
            return(newList);
        }
예제 #3
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);
        }
예제 #4
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);
            }
        }
예제 #5
0
        public static List <MayaObject> GetSelectedObjects(MFn.Type filter = MFn.Type.kInvalid)
        {
            MSelectionList selectionList = new MSelectionList();

            MGlobal.getActiveSelectionList(selectionList);
            IEnumerable <MDagPath> listAsDags;

            if (filter == MFn.Type.kInvalid)
            {
                listAsDags = selectionList.DagPaths();
            }
            else
            {
                listAsDags = selectionList.DagPaths(filter);
            }

            List <MayaObject> selectedObjects = new List <MayaObject>((int)selectionList.length);
            var mDagPaths = listAsDags as MDagPath[] ?? listAsDags.ToArray();

            selectedObjects.AddRange(mDagPaths.Select(dagObj => new MayaObject(dagObj)));

            return(selectedObjects);
        }
예제 #6
0
        public static MDagPath CombineMeshesUsingMEL(MSelectionList list, string resultName = null, bool keepHistory = true, MergeUVSetMethod mergeUVSetMethod = MergeUVSetMethod.ByName)
        {
            if (list == null || list.length == 0)
            {
                return(null);
            }
            List <string> dagNames = new List <string>();

            foreach (MDagPath dag in list.DagPaths())
            {
                dagNames.Add(dag.fullPathName);
            }
            return(CombineMeshesUsingMEL(dagNames, resultName, keepHistory, mergeUVSetMethod));
        }
예제 #7
0
 public static void IterateSelectedDags(Action <MDagPath> dealMethod, MFn.Type typeFilter = MFn.Type.kInvalid, MSelectionList list = null)
 {
     if (list == null)
     {
         list = GetSelectedList();
     }
     foreach (MDagPath dag in list.DagPaths())
     {
         if (typeFilter != MFn.Type.kInvalid)
         {
             if (!dag.hasFn(typeFilter))
             {
                 continue;
             }
         }
         dealMethod(dag);
     }
 }
예제 #8
0
 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");
         }
     }
 }
예제 #9
0
        internal void GetNewGeom()
        {
            if (base.firstRun)
            {
                firstRun = false;
            }
            else
            {
                if (SelectedItems != null)
                {
                    foreach (var itm in SelectedItems.Values)
                    {
                        itm.Dispose();
                    }
                }
            }


            MSelectionList selectionList = new MSelectionList();

            MGlobal.getActiveSelectionList(selectionList);


            var DagObjectList = selectionList.DagPaths(MFn.Type.kMesh).ToList();

            SelectedItems = new Dictionary <string, DMMesh>(DagObjectList.Count);

            foreach (var dag in DagObjectList)
            {
                var itm = new DMMesh(dag, space);
                itm.Changed += MObjOnChanged;
                itm.Deleted += MObjOnDeleted;
                SelectedItems.Add(itm.DagNode.uuid().asString(), itm);
            }

            if (firstRun)
            {
                firstRun = false;
            }

            OnNodeModified(true);
        }
예제 #10
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);
                }
            }
        }
예제 #11
0
        protected void __action(MoveToolAction flag)
        {
            //- Do the actual work here to move the objects	by vector
            MVector vector = __delta;

            if (flag == MoveToolAction.kUndoIt)
            {
                vector = -vector;
            }
            else
            {
                // all other cases identical
            }

            //- Create a selection list iterator
            MSelectionList slist = MGlobal.activeSelectionList;

            foreach (MDagPath mdagPath in slist.DagPaths())
            {
                MObject mComponent = mdagPath.node;

                try {
                    MFnTransform transFn = new MFnTransform(mdagPath);
                    try {
                        transFn.translateBy(vector, MSpace.Space.kWorld);
                        continue;
                    } catch (Exception) {
                        MGlobal.displayInfo("Error doing translate on transform");
                    }
                } catch (Exception) {
                    //- Not a transform
                }

                try
                {
                    var CVs = new MCCurveCV(mdagPath, mComponent);
                    try
                    {
                        foreach (MItCurveCV cvFn2 in CVs)
                        {
                            cvFn2.translateBy(vector, MSpace.Space.kWorld);
                        }
                        CVs.iter.updateCurve();
                    }
                    catch (System.Exception)
                    {
                        MGlobal.displayInfo("Error setting Curve CV");
                    }
                }
                catch (System.Exception)
                {
                    //- No Curve CV
                }

                try {
                    MItSurfaceCV sCvFn = new MItSurfaceCV(mdagPath, mComponent, true);
                    try {
                        while (!sCvFn.isDone)
                        {
                            while (!sCvFn.isRowDone)
                            {
                                sCvFn.translateBy(vector, MSpace.Space.kWorld);
                                sCvFn.next();
                            }
                            sCvFn.nextRow();
                        }
                        sCvFn.updateSurface();
                    } catch (Exception) {
                        MGlobal.displayInfo("Error setting Surface CV");
                    }
                } catch (Exception) {
                    //- No Surface CV
                }

                try {
                    var meshVertexEnum = new MCMeshVertex(mdagPath, mComponent);
                    try {
                        foreach (MItMeshVertex vtxFn in meshVertexEnum)
                        {
                            vtxFn.translateBy(vector, MSpace.Space.kWorld);
                        }
                        meshVertexEnum.iter.updateSurface();
                    }
                    catch (Exception)
                    {
                        MGlobal.displayInfo("Error setting Mesh Vertex");
                    }
                } catch (Exception) {
                    //- No Mesh Vertex
                }
            }
        }