Beispiel #1
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);
            }
        }