public static bool doCombinedValidate(MB2_MeshBakerRoot mom, MB_ObjsToCombineTypes objToCombineType, MB2_EditorMethodsInterface editorMethods){
		if (mom.textureBakeResults == null){
			Debug.LogError("Need to set Material Bake Result on " + mom);
			return false;
		}
		if (!(mom is MB2_TextureBaker)){
			MB2_TextureBaker tb = mom.GetComponent<MB2_TextureBaker>();
			if (tb != null && tb.textureBakeResults != mom.textureBakeResults){
				Debug.LogWarning("Material Bake Result on this component is not the same as the Material Bake Result on the MB2_TextureBaker.");
			}
		}
		
		List<GameObject> objsToMesh = mom.GetObjectsToCombine();
		for (int i = 0; i < objsToMesh.Count; i++){
			GameObject go = objsToMesh[i];
			if (go == null){
				Debug.LogError("The list of objects to combine contains a null at position." + i + " Select and use [shift] delete to remove");
				return false;					
			}
			for (int j = i + 1; j < objsToMesh.Count; j++){
				if (objsToMesh[i] == objsToMesh[j]){
					Debug.LogError("The list of objects to combine contains duplicates.");
					return false;	
				}
			}
			if (MB_Utility.GetGOMaterials(go) == null){
				Debug.LogError("Object " + go + " in the list of objects to be combined does not have a material");
				return false;
			}
			if (MB_Utility.GetMesh(go) == null){
				Debug.LogError("Object " + go + " in the list of objects to be combined does not have a mesh");
				return false;
			}
		}
		
		if (mom.textureBakeResults.doMultiMaterial){
			if (!validateSubmeshOverlap(mom)){//only warns currently
				return false;
			}
		}
		List<GameObject> objs = objsToMesh;
		if (mom is MB2_MeshBaker){
			MB2_TextureBaker tb = mom.GetComponent<MB2_TextureBaker>();
			if (((MB2_MeshBaker)mom).useObjsToMeshFromTexBaker && tb != null) objs = tb.objsToMesh; 
			if (objs == null || objs.Count == 0){
				Debug.LogError("No meshes to combine. Please assign some meshes to combine.");
				return false;
			}
			if (mom is MB2_MeshBaker && ((MB2_MeshBaker)mom).renderType == MB_RenderType.skinnedMeshRenderer){
				if (!editorMethods.ValidateSkinnedMeshes(objs)){
					return false;
				}
			}
		}
		
		if (editorMethods != null){
			editorMethods.CheckPrefabTypes(objToCombineType, objsToMesh);
		}
		return true;
	}
	static bool validateSubmeshOverlap(MB2_MeshBakerRoot mom){
		List<GameObject> objsToMesh = mom.GetObjectsToCombine();
		for (int i = 0; i < objsToMesh.Count; i++){
			Mesh m = MB_Utility.GetMesh(objsToMesh[i]);
			if (MB_Utility.doSubmeshesShareVertsOrTris(m) != 0){
				Debug.LogWarning("Object " + objsToMesh[i] + " in the list of objects to combine has overlapping submeshes (submeshes share vertices). If the UVs associated with the shared vertices are important then this bake may not work. If you are using multiple materials then this object can only be combined with objects that use the exact same set of textures (each atlas contains one texture). There may be other undesirable side affects as well. Mesh Master, available in the asset store can fix overlapping submeshes.");	
				return true;
			}
		}
		return true;
	}	
예제 #3
0
    static bool validateSubmeshOverlap(MB2_MeshBakerRoot mom)
    {
        List <GameObject> objsToMesh = mom.GetObjectsToCombine();

        for (int i = 0; i < objsToMesh.Count; i++)
        {
            Mesh m = MB_Utility.GetMesh(objsToMesh[i]);
            if (MB_Utility.doSubmeshesShareVertsOrTris(m) != 0)
            {
                Debug.LogError("Object " + objsToMesh[i] + " in the list of objects to combine has overlapping submeshes. This object can only be combined with objects that use the exact same set of textures. There may be other undesirable side affects as well.");
                return(true);
            }
        }
        return(true);
    }
예제 #4
0
    static bool validateSubmeshOverlap(MB2_MeshBakerRoot mom)
    {
        List <GameObject> objsToMesh = mom.GetObjectsToCombine();

        for (int i = 0; i < objsToMesh.Count; i++)
        {
            Mesh m = MB_Utility.GetMesh(objsToMesh[i]);
            if (MB_Utility.doSubmeshesShareVertsOrTris(m) != 0)
            {
                Debug.LogWarning("Object " + objsToMesh[i] + " in the list of objects to combine has overlapping submeshes (submeshes share vertices). If the UVs associated with the shared vertices are important then this bake may not work. If you are using multiple materials then this object can only be combined with objects that use the exact same set of textures (each atlas contains one texture). There may be other undesirable side affects as well. Mesh Master, available in the asset store can fix overlapping submeshes.");
                return(true);
            }
        }
        return(true);
    }
    void addSelectedObjects()
    {
        MB2_MeshBakerRoot mom = (MB2_MeshBakerRoot)target;

        if (mom == null)
        {
            Debug.LogError("Must select a target MeshBaker to add objects to");
            return;
        }
        List <UnityEngine.GameObject> newMomObjs = GetFilteredList();

        Undo.RegisterUndo(mom, "Add Objects");
        List <UnityEngine.GameObject> momObjs = mom.GetObjectsToCombine();
        int numAdded = 0;

        for (int i = 0; i < newMomObjs.Count; i++)
        {
            if (!momObjs.Contains(newMomObjs[i]))
            {
                momObjs.Add(newMomObjs[i]);
                numAdded++;
            }
        }
        SerializedObject so = new SerializedObject(mom);

        so.SetIsDifferentCacheDirty();

        if (numAdded == 0)
        {
            Debug.LogWarning("Added 0 objects. Make sure some or all objects are selected in the hierarchy view. Also check ths 'Only Static Objects', 'Using Material' and 'Using UnityEngine.Shader' settings");
        }
        else
        {
            Debug.Log("Added " + numAdded + " objects to " + mom.name);
        }
    }
예제 #6
0
    public static bool doCombinedValidate(MB2_MeshBakerRoot mom, MB_ObjsToCombineTypes objToCombineType)
    {
//		MB2_MeshBaker mom = (MB2_MeshBaker) target;

        if (mom.textureBakeResults == null)
        {
            Debug.LogError("Need to set textureBakeResults");
            return(false);
        }
        if (!(mom is MB2_TextureBaker))
        {
            MB2_TextureBaker tb = mom.GetComponent <MB2_TextureBaker>();
            if (tb != null && tb.textureBakeResults != mom.textureBakeResults)
            {
                Debug.LogWarning("textureBakeResults on this component is not the same as the textureBakeResults on the MB2_TextureBaker.");
            }
        }

        List <GameObject> objsToMesh = mom.GetObjectsToCombine();

        for (int i = 0; i < objsToMesh.Count; i++)
        {
            GameObject go = objsToMesh[i];
            if (go == null)
            {
                Debug.LogError("The list of objects to combine contains nulls.");
                return(false);
            }
            for (int j = i + 1; j < objsToMesh.Count; j++)
            {
                if (objsToMesh[i] == objsToMesh[j])
                {
                    Debug.LogError("The list of objects to combine contains duplicates.");
                    return(false);
                }
            }
            if (MB_Utility.GetGOMaterials(go) == null)
            {
                Debug.LogError("Object " + go + " in the list of objects to be combined does not have a material");
                return(false);
            }
            if (MB_Utility.GetMesh(go) == null)
            {
                Debug.LogError("Object " + go + " in the list of objects to be combined does not have a mesh");
                return(false);
            }
        }

        if (mom.textureBakeResults.doMultiMaterial)
        {
            if (!validateSubmeshOverlap(mom))             //only warns currently
            {
                return(false);
            }
        }
        List <GameObject> objs = objsToMesh;

        if (mom is MB2_MeshBaker)
        {
            MB2_TextureBaker tb = mom.GetComponent <MB2_TextureBaker>();
            if (((MB2_MeshBaker)mom).useObjsToMeshFromTexBaker && tb != null)
            {
                objs = tb.objsToMesh;
            }
            if (objs == null || objs.Count == 0)
            {
                Debug.LogError("No meshes to combine. Please assign some meshes to combine.");
                return(false);
            }
        }

#if UNITY_EDITOR
        for (int i = 0; i < objsToMesh.Count; i++)
        {
            UnityEditor.PrefabType pt = UnityEditor.PrefabUtility.GetPrefabType(objsToMesh[i]);
            if (pt == UnityEditor.PrefabType.None ||
                pt == UnityEditor.PrefabType.PrefabInstance ||
                pt == UnityEditor.PrefabType.ModelPrefabInstance ||
                pt == UnityEditor.PrefabType.DisconnectedPrefabInstance ||
                pt == UnityEditor.PrefabType.DisconnectedModelPrefabInstance)
            {
                // these are scene objects
                if (objToCombineType == MB_ObjsToCombineTypes.prefabOnly)
                {
                    Debug.LogWarning("The list of objects to combine contains scene objects. You probably want prefabs." + objsToMesh[i] + " is a scene object");
                }
            }
            else if (objToCombineType == MB_ObjsToCombineTypes.sceneObjOnly)
            {
                //these are prefabs
                Debug.LogWarning("The list of objects to combine contains prefab objects. You probably want scene objects." + objsToMesh[i] + " is a prefab object");
            }
        }
#endif
        return(true);
    }
예제 #7
0
    public static bool doCombinedValidate(MB2_MeshBakerRoot mom, MB_ObjsToCombineTypes objToCombineType, MB2_EditorMethodsInterface editorMethods)
    {
        if (mom.textureBakeResults == null)
        {
            Debug.LogError("Need to set Material Bake Result on " + mom);
            return(false);
        }
        if (!(mom is MB2_TextureBaker))
        {
            MB2_TextureBaker tb = mom.GetComponent <MB2_TextureBaker>();
            if (tb != null && tb.textureBakeResults != mom.textureBakeResults)
            {
                Debug.LogWarning("Material Bake Result on this component is not the same as the Material Bake Result on the MB2_TextureBaker.");
            }
        }

        List <GameObject> objsToMesh = mom.GetObjectsToCombine();

        for (int i = 0; i < objsToMesh.Count; i++)
        {
            GameObject go = objsToMesh[i];
            if (go == null)
            {
                Debug.LogError("The list of objects to combine contains a null at position." + i + " Select and use [shift] delete to remove");
                return(false);
            }
            for (int j = i + 1; j < objsToMesh.Count; j++)
            {
                if (objsToMesh[i] == objsToMesh[j])
                {
                    Debug.LogError("The list of objects to combine contains duplicates.");
                    return(false);
                }
            }
            if (MB_Utility.GetGOMaterials(go) == null)
            {
                Debug.LogError("Object " + go + " in the list of objects to be combined does not have a material");
                return(false);
            }
            if (MB_Utility.GetMesh(go) == null)
            {
                Debug.LogError("Object " + go + " in the list of objects to be combined does not have a mesh");
                return(false);
            }
        }

        if (mom.textureBakeResults.doMultiMaterial)
        {
            if (!validateSubmeshOverlap(mom))             //only warns currently
            {
                return(false);
            }
        }
        List <GameObject> objs = objsToMesh;

        if (mom is MB2_MeshBaker)
        {
            MB2_TextureBaker tb = mom.GetComponent <MB2_TextureBaker>();
            if (((MB2_MeshBaker)mom).useObjsToMeshFromTexBaker && tb != null)
            {
                objs = tb.objsToMesh;
            }
            if (objs == null || objs.Count == 0)
            {
                Debug.LogError("No meshes to combine. Please assign some meshes to combine.");
                return(false);
            }
            if (mom is MB2_MeshBaker && ((MB2_MeshBaker)mom).renderType == MB_RenderType.skinnedMeshRenderer)
            {
                if (!editorMethods.ValidateSkinnedMeshes(objs))
                {
                    return(false);
                }
            }
        }

        if (editorMethods != null)
        {
            editorMethods.CheckPrefabTypes(objToCombineType, objsToMesh);
        }
        return(true);
    }
    void addSelectedObjects()
    {
        MB2_MeshBakerRoot mom = (MB2_MeshBakerRoot)target;

        if (mom == null)
        {
            Debug.LogError("Must select a target MeshBaker to add objects to");
            return;
        }
        GameObject dontAddMe = null;
        Renderer   r         = MB_Utility.GetRenderer(mom.gameObject);

        if (r != null)          //make sure that this MeshBaker object is not in list
        {
            dontAddMe = r.gameObject;
        }

        int numAdded = 0;
        List <GameObject> momObjs    = mom.GetObjectsToCombine();
        List <GameObject> newMomObjs = new List <GameObject>();

        GameObject[] gos = Selection.gameObjects;
        if (gos.Length == 0)
        {
            Debug.LogWarning("No objects selected in hierarchy view. Nothing added.");
        }

        for (int i = 0; i < gos.Length; i++)
        {
            GameObject go  = gos[i];
            Renderer[] mrs = go.GetComponentsInChildren <Renderer>();
            for (int j = 0; j < mrs.Length; j++)
            {
                if (!momObjs.Contains(mrs[j].gameObject) && !newMomObjs.Contains(mrs[j].gameObject))
                {
                    bool addMe = true;
                    if (!mrs[j].gameObject.isStatic && onlyStaticObjects)
                    {
                        addMe = false;
                    }

                    Mesh mm = MB_Utility.GetMesh(mrs[j].gameObject);
                    if (mm != null)
                    {
                        Rect dummy = new Rect();
                        if (MB_Utility.hasOutOfBoundsUVs(mm, ref dummy))
                        {
                            Debug.LogWarning("Object " + mrs[j].gameObject.name + " uses uvs that are outside the range (0,1)" +
                                             "this object can only be combined with other objects that use the exact same set of source textures " +
                                             " this object has not been added. You will have to add it manually");
                            if (shaderMat != null)
                            {
                                addMe = false;
                            }
                        }
                    }

                    if (shaderMat != null)
                    {
                        Material[] nMats      = mrs[j].sharedMaterials;
                        bool       usesShader = false;
                        foreach (Material nMat in nMats)
                        {
                            if (nMat != null && nMat.shader == shaderMat.shader)
                            {
                                usesShader = true;
                            }
                        }
                        if (!usesShader)
                        {
                            addMe = false;
                        }
                    }

                    if (mat != null)
                    {
                        Material[] nMats   = mrs[j].sharedMaterials;
                        bool       usesMat = false;
                        foreach (Material nMat in nMats)
                        {
                            if (nMat == mat)
                            {
                                usesMat = true;
                            }
                        }
                        if (!usesMat)
                        {
                            addMe = false;
                        }
                    }

                    if (addMe && mrs[j].gameObject != dontAddMe)
                    {
                        if (!newMomObjs.Contains(mrs[j].gameObject))
                        {
                            newMomObjs.Add(mrs[j].gameObject);
                        }
                        numAdded++;
                    }
                }
            }
        }

        Undo.RegisterUndo(mom, "Add Objects");
        for (int i = 0; i < newMomObjs.Count; i++)
        {
            mom.GetObjectsToCombine().Add(newMomObjs[i]);
        }
        SerializedObject so = new SerializedObject(mom);

        so.SetIsDifferentCacheDirty();

        if (numAdded == 0)
        {
            Debug.LogWarning("Added 0 objects. Make sure some or all objects are selected in the hierarchy view. Also check ths 'Only Static Objects' and 'Only Objects Using Shader' settings");
        }
        else
        {
            Debug.Log("Added " + numAdded + " objects to " + mom.name);
        }
    }