Exemplo n.º 1
0
        public int Compare(GameObjectFilterInfo a, GameObjectFilterInfo b)
        {
            int compareVal = 0;

            if (b.go.activeInHierarchy == true && a.go.activeInHierarchy == false)
            {
                compareVal = -1;
            }
            if (b.go.activeInHierarchy == false && a.go.activeInHierarchy == true)
            {
                compareVal = 1;
            }
            return(compareVal);
        }
        public int Compare(GameObjectFilterInfo a, GameObjectFilterInfo b)
        {
            int staticCompare = 0;

            if (b.isStatic == true && a.isStatic == false)
            {
                staticCompare = -1;
            }
            if (b.isStatic == false && a.isStatic == true)
            {
                staticCompare = 1;
            }
            return(staticCompare);
        }
Exemplo n.º 3
0
        public int Compare(GameObjectFilterInfo a, GameObjectFilterInfo b)
        {
            int renderTypeCompare = 0;

            if (b.isMeshRenderer == true && a.isMeshRenderer == false)
            {
                renderTypeCompare = -1;
            }
            if (b.isMeshRenderer == false && a.isMeshRenderer == true)
            {
                renderTypeCompare = 1;
            }
            return(renderTypeCompare);
        }
        public int Compare(GameObjectFilterInfo a, GameObjectFilterInfo b)
        {
            int alreadyAddedCompare = 0;

            if (b.alreadyInBakerList == true && a.alreadyInBakerList == false)
            {
                alreadyAddedCompare = -1;
            }
            if (b.alreadyInBakerList == false && a.alreadyInBakerList == true)
            {
                alreadyAddedCompare = 1;
            }
            return(alreadyAddedCompare);
        }
Exemplo n.º 5
0
        public string GetDescription(IGroupByFilter[] groupBy, GameObjectFilterInfo fi)
        {
            string desc = "";

            if (groupBy != null)
            {
                for (int i = 0; i < groupBy.Length; i++)
                {
                    desc += groupBy[i].GetDescription(fi) + " ";
                }
                return(desc);
            }
            else
            {
                return("todo");
            }
        }
Exemplo n.º 6
0
        public int CompareTo(System.Object obj)
        {
            if (obj is GameObjectFilterInfo)
            {
                GameObjectFilterInfo gobj = (GameObjectFilterInfo)obj;
                int gb;

                for (int i = 0; i < filters.Length; i++)
                {
                    if (filters[i] != null)
                    {
                        gb = filters[i].Compare(this, gobj);
                        if (gb != 0)
                        {
                            return(gb);
                        }
                    }
                }
            }
            return(0);
        }
 public string GetDescription(GameObjectFilterInfo fi)
 {
     return("alreadyAdded=" + fi.alreadyInBakerList);
 }
Exemplo n.º 8
0
 public int Compare(GameObjectFilterInfo a, GameObjectFilterInfo b)
 {
     return(a.shaderName.CompareTo(b.shaderName));
 }
Exemplo n.º 9
0
 public string GetDescription(GameObjectFilterInfo fi)
 {
     return(fi.isMeshRenderer ? "MeshRenderer" : "SkinnedMeshRenderer");
 }
 public string GetDescription(GameObjectFilterInfo fi)
 {
     return("isStatic=" + fi.isStatic);
 }
 public string GetDescription(GameObjectFilterInfo fi)
 {
     return("material=" + fi.materialName);
 }
        /* tried to see if the MultiMaterialConfig could be done using the GroupBy filters. Saddly it didn't work */
        public static void ConfigureMutiMaterialsFromObjsToCombine2(MB3_TextureBaker mom, SerializedProperty resultMaterials, SerializedObject textureBaker)
        {
            if (mom.GetObjectsToCombine().Count == 0)
            {
                Debug.LogError("You need to add some objects to combine before building the multi material list.");
                return;
            }
            if (resultMaterials.arraySize > 0)
            {
                Debug.LogError("You already have some source to combined material mappings configured. You must remove these before doing this operation.");
                return;
            }
            if (mom.textureBakeResults == null)
            {
                Debug.LogError("Texture Bake Result asset must be set before using this operation.");
                return;
            }

            //validate that the objects to be combined are valid
            for (int i = 0; i < mom.GetObjectsToCombine().Count; i++)
            {
                GameObject go = mom.GetObjectsToCombine()[i];
                if (go == null)
                {
                    Debug.LogError("Null object in list of objects to combine at position " + i);
                    return;
                }
                Renderer r = go.GetComponent <Renderer>();
                if (r == null || (!(r is MeshRenderer) && !(r is SkinnedMeshRenderer)))
                {
                    Debug.LogError("GameObject at position " + i + " in list of objects to combine did not have a renderer");
                    return;
                }
                if (r.sharedMaterial == null)
                {
                    Debug.LogError("GameObject at position " + i + " in list of objects to combine has a null material");
                    return;
                }
            }

            IGroupByFilter[] filters = new IGroupByFilter[3];
            filters[0] = new GroupByOutOfBoundsUVs();
            filters[1] = new GroupByShader();
            filters[2] = new MB3_GroupByStandardShaderType();

            List <GameObjectFilterInfo> gameObjects = new List <GameObjectFilterInfo>();
            HashSet <GameObject>        objectsAlreadyIncludedInBakers = new HashSet <GameObject>();

            for (int i = 0; i < mom.GetObjectsToCombine().Count; i++)
            {
                GameObjectFilterInfo goaw = new GameObjectFilterInfo(mom.GetObjectsToCombine()[i], objectsAlreadyIncludedInBakers, filters);
                if (goaw.materials.Length > 0) //don't consider renderers with no materials
                {
                    gameObjects.Add(goaw);
                }
            }

            //analyse meshes
            Dictionary <int, MB_Utility.MeshAnalysisResult> meshAnalysisResultCache = new Dictionary <int, MB_Utility.MeshAnalysisResult>();
            int totalVerts = 0;

            for (int i = 0; i < gameObjects.Count; i++)
            {
                //string rpt = String.Format("Processing {0} [{1} of {2}]", gameObjects[i].go.name, i, gameObjects.Count);
                //EditorUtility.DisplayProgressBar("Analysing Scene", rpt + " A", .6f);
                Mesh mm     = MB_Utility.GetMesh(gameObjects[i].go);
                int  nVerts = 0;
                if (mm != null)
                {
                    nVerts += mm.vertexCount;
                    MB_Utility.MeshAnalysisResult mar;
                    if (!meshAnalysisResultCache.TryGetValue(mm.GetInstanceID(), out mar))
                    {
                        //EditorUtility.DisplayProgressBar("Analysing Scene", rpt + " Check Out Of Bounds UVs", .6f);
                        MB_Utility.hasOutOfBoundsUVs(mm, ref mar);
                        //Rect dummy = mar.uvRect;
                        MB_Utility.doSubmeshesShareVertsOrTris(mm, ref mar);
                        meshAnalysisResultCache.Add(mm.GetInstanceID(), mar);
                    }
                    if (mar.hasOutOfBoundsUVs)
                    {
                        int w = (int)mar.uvRect.width;
                        int h = (int)mar.uvRect.height;
                        gameObjects[i].outOfBoundsUVs = true;
                        gameObjects[i].warning       += " [WARNING: has uvs outside the range (0,1) tex is tiled " + w + "x" + h + " times]";
                    }
                    if (mar.hasOverlappingSubmeshVerts)
                    {
                        gameObjects[i].submeshesOverlap = true;
                        gameObjects[i].warning         += " [WARNING: Submeshes share verts or triangles. 'Multiple Combined Materials' feature may not work.]";
                    }
                }
                totalVerts += nVerts;
                //EditorUtility.DisplayProgressBar("Analysing Scene", rpt + " Validate OBuvs Multi Material", .6f);
                Renderer mr = gameObjects[i].go.GetComponent <Renderer>();
                if (!MB_Utility.AreAllSharedMaterialsDistinct(mr.sharedMaterials))
                {
                    gameObjects[i].warning += " [WARNING: Object uses same material on multiple submeshes. This may produce poor results when used with multiple materials or fix out of bounds uvs.]";
                }
            }

            List <GameObjectFilterInfo> objsNotAddedToBaker = new List <GameObjectFilterInfo>();

            Dictionary <GameObjectFilterInfo, List <List <GameObjectFilterInfo> > > gs2bakeGroupMap = MB3_MeshBakerEditorWindow.sortIntoBakeGroups3(gameObjects, objsNotAddedToBaker, filters, false, mom.maxAtlasSize);

            mom.resultMaterials = new MB_MultiMaterial[gs2bakeGroupMap.Keys.Count];
            string pth        = AssetDatabase.GetAssetPath(mom.textureBakeResults);
            string baseName   = Path.GetFileNameWithoutExtension(pth);
            string folderPath = pth.Substring(0, pth.Length - baseName.Length - 6);
            int    k          = 0;

            foreach (GameObjectFilterInfo m in gs2bakeGroupMap.Keys)
            {
                MB_MultiMaterial mm = mom.resultMaterials[k] = new MB_MultiMaterial();
                mm.sourceMaterials = new List <Material>();
                mm.sourceMaterials.Add(m.materials[0]);
                string   matName = folderPath + baseName + "-mat" + k + ".mat";
                Material newMat  = new Material(Shader.Find("Diffuse"));
                MB3_TextureBaker.ConfigureNewMaterialToMatchOld(newMat, m.materials[0]);
                AssetDatabase.CreateAsset(newMat, matName);
                mm.combinedMaterial = (Material)AssetDatabase.LoadAssetAtPath(matName, typeof(Material));
                k++;
            }
            MBVersionEditor.UpdateIfDirtyOrScript(textureBaker);
        }
Exemplo n.º 13
0
 public int Compare(GameObjectFilterInfo a, GameObjectFilterInfo b)
 {
     return(a.shaderName.CompareTo(b.standardShaderBlendModesName));
 }
Exemplo n.º 14
0
 public string GetDescription(GameObjectFilterInfo fi)
 {
     return(fi.go.activeInHierarchy ? "Enabled" : "Disabled");
 }
Exemplo n.º 15
0
 public int Compare(GameObjectFilterInfo a, GameObjectFilterInfo b)
 {
     return(b.lightmapIndex - a.lightmapIndex);
 }
 public int Compare(GameObjectFilterInfo a, GameObjectFilterInfo b)
 {
     return(a.materialName.CompareTo(b.materialName));
 }
Exemplo n.º 17
0
 public string GetDescription(GameObjectFilterInfo fi)
 {
     return("shader=" + fi.shaderName);
 }
 public int Compare(GameObjectFilterInfo a, GameObjectFilterInfo b)
 {
     return(Convert.ToInt32(b.outOfBoundsUVs) - Convert.ToInt32(a.outOfBoundsUVs));
 }
 public string GetDescription(GameObjectFilterInfo fi)
 {
     return("OutOfBoundsUVs=" + fi.outOfBoundsUVs);
 }
Exemplo n.º 20
0
 public string GetDescription(GameObjectFilterInfo fi)
 {
     return("renderingMode=" + fi.standardShaderBlendModesName);
 }
Exemplo n.º 21
0
 public string GetDescription(GameObjectFilterInfo fi)
 {
     return("lightmapIndex=" + fi.lightmapIndex);
 }