예제 #1
0
 public bool CheckPrefabTypes(MB_ObjsToCombineTypes objToCombineType, List <GameObject> objsToMesh)
 {
     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. If using scene objects ensure position is zero, rotation is zero and scale is one. Translation, Rotation and Scale will be baked into the generated mesh." + objsToMesh[i] + " is a scene object");
                 return(false);
             }
         }
         else if (objToCombineType == MB_ObjsToCombineTypes.sceneObjOnly)
         {
             //these are prefabs
             Debug.LogWarning("The list of objects to combine contains prefab assets. You probably want scene objects." + objsToMesh[i] + " is a prefab object");
             return(false);
         }
     }
     return(true);
 }
	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;
	}
 public bool CheckPrefabTypes(MB_ObjsToCombineTypes objToCombineType, List<GameObject> objsToMesh)
 {
     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. If using scene objects ensure position is zero, rotation is zero and scale is one. Translation, Rotation and Scale will be baked into the generated mesh." + objsToMesh[i] + " is a scene object");
                 return false;
             }
         } else if (objToCombineType == MB_ObjsToCombineTypes.sceneObjOnly){
             //these are prefabs
             Debug.LogWarning("The list of objects to combine contains prefab assets. You probably want scene objects." + objsToMesh[i] + " is a prefab object");
             return false;
         }
     }
     return true;
 }
예제 #4
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);
    }
예제 #5
0
    public static bool DoCombinedValidate(MB3_MeshBakerRoot mom, MB_ObjsToCombineTypes objToCombineType, MB2_EditorMethodsInterface editorMethods, MB2_ValidationLevel validationLevel)
    {
        if (mom.textureBakeResults == null)
        {
            Debug.LogError("Need to set Texture Bake Result on " + mom);
            return(false);
        }
        if (mom is MB3_MeshBakerCommon)
        {
            MB3_MeshBakerCommon momMB = (MB3_MeshBakerCommon)mom;
            MB3_TextureBaker    tb    = momMB.GetTextureBaker();
            if (tb != null && tb.textureBakeResults != mom.textureBakeResults)
            {
                Debug.LogWarning("Texture Bake Result on this component is not the same as the Texture Bake Result on the MB3_TextureBaker.");
            }
        }

        Dictionary <int, MB_Utility.MeshAnalysisResult> meshAnalysisResultCache = null;

        if (validationLevel == MB2_ValidationLevel.robust)
        {
            meshAnalysisResultCache = new Dictionary <int, MB_Utility.MeshAnalysisResult>();
        }
        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 at " + i + " and " + j);
                    return(false);
                }
            }
            if (MB_Utility.GetGOMaterials(go).Length == 0)
            {
                Debug.LogError("Object " + go + " in the list of objects to be combined does not have a material");
                return(false);
            }
            Mesh m = MB_Utility.GetMesh(go);
            if (m == null)
            {
                Debug.LogError("Object " + go + " in the list of objects to be combined does not have a mesh");
                return(false);
            }
            if (m != null)              //This check can be very expensive and it only warns so only do this if we are in the editor.
            {
                if (!Application.isEditor &&
                    Application.isPlaying &&
                    mom.textureBakeResults.doMultiMaterial &&
                    validationLevel >= MB2_ValidationLevel.robust)
                {
                    MB_Utility.MeshAnalysisResult mar;
                    if (!meshAnalysisResultCache.TryGetValue(m.GetInstanceID(), out mar))
                    {
                        MB_Utility.doSubmeshesShareVertsOrTris(m, ref mar);
                        meshAnalysisResultCache.Add(m.GetInstanceID(), mar);
                    }
                    if (mar.hasOverlappingSubmeshVerts)
                    {
                        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.");
                    }
                }
            }
        }


        List <GameObject> objs = objsToMesh;

        if (mom is MB3_MeshBaker)
        {
            objs = mom.GetObjectsToCombine();
            //if (((MB3_MeshBaker)mom).useObjsToMeshFromTexBaker && tb != null) objs = tb.GetObjectsToCombine();
            if (objs == null || objs.Count == 0)
            {
                Debug.LogError("No meshes to combine. Please assign some meshes to combine.");
                return(false);
            }
            if (mom is MB3_MeshBaker && ((MB3_MeshBaker)mom).meshCombiner.settings.renderType == MB_RenderType.skinnedMeshRenderer)
            {
                if (!editorMethods.ValidateSkinnedMeshes(objs))
                {
                    return(false);
                }
            }
        }

        if (editorMethods != null)
        {
            editorMethods.CheckPrefabTypes(objToCombineType, objsToMesh);
        }
        return(true);
    }
예제 #6
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);
    }
예제 #7
0
	public static bool DoCombinedValidate(MB3_MeshBakerRoot mom, MB_ObjsToCombineTypes objToCombineType, MB2_EditorMethodsInterface editorMethods, MB2_ValidationLevel validationLevel){
		if (mom.textureBakeResults == null){
			Debug.LogError("Need to set Material Bake Result on " + mom);
			return false;
		}
		if (mom is MB3_MeshBakerCommon){
			MB3_MeshBakerCommon momMB = (MB3_MeshBakerCommon) mom;
			MB3_TextureBaker tb = momMB.GetTextureBaker();
			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 MB3_TextureBaker.");
			}
		}

		Dictionary<int,MB_Utility.MeshAnalysisResult> meshAnalysisResultCache = null;
		if (validationLevel == MB2_ValidationLevel.robust){
			meshAnalysisResultCache = new Dictionary<int, MB_Utility.MeshAnalysisResult>();
		}
		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 at " + i + " and " + j);
					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;
			}
			Mesh m = MB_Utility.GetMesh(go);
			if (m == null){
				Debug.LogError("Object " + go + " in the list of objects to be combined does not have a mesh");
				return false;
			}
			if (m != null){ //This check can be very expensive and it only warns so only do this if we are in the editor.
				if (!Application.isEditor && 
				    Application.isPlaying &&
					mom.textureBakeResults.doMultiMaterial && 
					validationLevel >= MB2_ValidationLevel.robust){
					MB_Utility.MeshAnalysisResult mar;
					if (!meshAnalysisResultCache.TryGetValue(m.GetInstanceID(),out mar)){
						MB_Utility.doSubmeshesShareVertsOrTris(m,ref mar);
						meshAnalysisResultCache.Add (m.GetInstanceID(),mar);
					}
					if (mar.hasOverlappingSubmeshVerts){
						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.");	
					}
				}
			}
		}

		
		List<GameObject> objs = objsToMesh;
		
		if (mom is MB3_MeshBaker)
		{
			objs = mom.GetObjectsToCombine();
			//if (((MB3_MeshBaker)mom).useObjsToMeshFromTexBaker && tb != null) objs = tb.GetObjectsToCombine(); 
			if (objs == null || objs.Count == 0)
			{
				Debug.LogError("No meshes to combine. Please assign some meshes to combine.");
				return false;
			}
			if (mom is MB3_MeshBaker && ((MB3_MeshBaker)mom).meshCombiner.renderType == MB_RenderType.skinnedMeshRenderer){
				if (!editorMethods.ValidateSkinnedMeshes(objs))
				{
					return false;
				}
			}
		}
		
		if (editorMethods != null){
			editorMethods.CheckPrefabTypes(objToCombineType, objsToMesh);
		}
		return true;
	}
예제 #8
0
    public static bool DoCombinedValidate(MB3_MeshBakerRoot mom, MB_ObjsToCombineTypes objToCombineType, MB2_EditorMethodsInterface editorMethods, MB2_ValidationLevel validationLevel)
    {
        if (mom.textureBakeResults == null)
        {
            Debug.LogError("Need to set Material Bake Result on " + mom);
            return(false);
        }
        if (mom is MB3_MeshBakerCommon)
        {
            MB3_MeshBakerCommon mb3_MeshBakerCommon = (MB3_MeshBakerCommon)mom;
            MB3_TextureBaker    textureBaker        = mb3_MeshBakerCommon.GetTextureBaker();
            if (textureBaker != null && textureBaker.textureBakeResults != mom.textureBakeResults)
            {
                Debug.LogWarning("Material Bake Result on this component is not the same as the Material Bake Result on the MB3_TextureBaker.");
            }
        }
        Dictionary <int, MB_Utility.MeshAnalysisResult> dictionary = null;

        if (validationLevel == MB2_ValidationLevel.robust)
        {
            dictionary = new Dictionary <int, MB_Utility.MeshAnalysisResult>();
        }
        List <GameObject> objectsToCombine = mom.GetObjectsToCombine();

        for (int i = 0; i < objectsToCombine.Count; i++)
        {
            GameObject gameObject = objectsToCombine[i];
            if (gameObject == 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 < objectsToCombine.Count; j++)
            {
                if (objectsToCombine[i] == objectsToCombine[j])
                {
                    Debug.LogError(string.Concat(new object[]
                    {
                        "The list of objects to combine contains duplicates at ",
                        i,
                        " and ",
                        j
                    }));
                    return(false);
                }
            }
            if (MB_Utility.GetGOMaterials(gameObject) == null)
            {
                Debug.LogError("Object " + gameObject + " in the list of objects to be combined does not have a material");
                return(false);
            }
            Mesh mesh = MB_Utility.GetMesh(gameObject);
            if (mesh == null)
            {
                Debug.LogError("Object " + gameObject + " in the list of objects to be combined does not have a mesh");
                return(false);
            }
            if (mesh != null && !Application.isEditor && Application.isPlaying && mom.textureBakeResults.doMultiMaterial && validationLevel >= MB2_ValidationLevel.robust)
            {
                MB_Utility.MeshAnalysisResult value;
                if (!dictionary.TryGetValue(mesh.GetInstanceID(), out value))
                {
                    MB_Utility.doSubmeshesShareVertsOrTris(mesh, ref value);
                    dictionary.Add(mesh.GetInstanceID(), value);
                }
                if (value.hasOverlappingSubmeshVerts)
                {
                    Debug.LogWarning("Object " + objectsToCombine[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.");
                }
            }
        }
        if (mom is MB3_MeshBaker)
        {
            List <GameObject> objectsToCombine2 = mom.GetObjectsToCombine();
            if (objectsToCombine2 == null || objectsToCombine2.Count == 0)
            {
                Debug.LogError("No meshes to combine. Please assign some meshes to combine.");
                return(false);
            }
            if (mom is MB3_MeshBaker && ((MB3_MeshBaker)mom).meshCombiner.renderType == MB_RenderType.skinnedMeshRenderer && !editorMethods.ValidateSkinnedMeshes(objectsToCombine2))
            {
                return(false);
            }
        }
        if (editorMethods != null)
        {
            editorMethods.CheckPrefabTypes(objToCombineType, objectsToCombine);
        }
        return(true);
    }
    bool doCombinedValidate(MB_ObjsToCombineTypes objToCombineType)
    {
        MB_MeshBaker mom = (MB_MeshBaker)target;

        for (int i = 0; i < mom.objsToMesh.Count; i++)
        {
            if (mom.objsToMesh[i] == null)
            {
                Debug.LogError("The list of objects to combine contains nulls.");
                return(false);
            }
            for (int j = i + 1; j < mom.objsToMesh.Count; j++)
            {
                if (mom.objsToMesh[i] == mom.objsToMesh[j])
                {
                    Debug.LogError("The list of objects to combine contains duplicates.");
                    return(false);
                }
            }
        }

        if (mom.doMultiMaterial)
        {
            if (!validateMultipleMaterials())
            {
                return(false);
            }
            if (!validateSubmeshOverlap())             //only warns currently
            {
                return(false);
            }
        }
        else
        {
            if (mom.resultMaterial == null)
            {
                Debug.LogError("Please assign a result material. The combined mesh will use this material.");
                return(false);
            }
        }
        if (mom.objsToMesh == null || mom.objsToMesh.Count == 0)
        {
            Debug.LogError("No meshes to combine. Please assign some meshes to combine.");
            return(false);
        }
        if (mom.atlasPadding < 0)
        {
            Debug.LogError("Atlas padding must be zero or greater.");
            return(false);
        }

        for (int i = 0; i < mom.objsToMesh.Count; i++)
        {
            UnityEditor.PrefabType pt = UnityEditor.PrefabUtility.GetPrefabType(mom.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." + mom.objsToMesh[i] + " is a scene object");
                }
            }
            else if (objToCombineType == MB_ObjsToCombineTypes.sceneObjOnly)
            {
                //these are prefabs
                Debug.LogError("The list of objects to combine contains prefab objects. You probably want scene objects." + mom.objsToMesh[i] + " is a prefab object");
            }
        }
        return(true);
    }
예제 #10
0
    public static bool DoCombinedValidate(MB3_MeshBakerRoot mom, MB_ObjsToCombineTypes objToCombineType, MB2_EditorMethodsInterface editorMethods, MB2_ValidationLevel validationLevel)
    {
        if (mom.textureBakeResults == null)
        {
            Debug.LogError("Need to set Texture Bake Result on " + mom);
            return(false);
        }
        if (mom is MB3_MeshBakerCommon)
        {
            MB3_MeshBakerCommon momMB = (MB3_MeshBakerCommon)mom;
            MB3_TextureBaker    tb    = momMB.GetTextureBaker();
            if (tb != null && tb.textureBakeResults != mom.textureBakeResults)
            {
                Debug.LogWarning("Texture Bake Result on this component is not the same as the Texture Bake Result on the MB3_TextureBaker.");
            }
        }

        Dictionary <int, MB_Utility.MeshAnalysisResult> meshAnalysisResultCache = null;

        if (validationLevel == MB2_ValidationLevel.robust)
        {
            meshAnalysisResultCache = new Dictionary <int, MB_Utility.MeshAnalysisResult>();
        }
        List <GameObject>             objsToMesh  = mom.GetObjectsToCombine();
        Dictionary <string, Material> matName2Mat = new Dictionary <string, Material>();

        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 at " + i + " and " + j);
                    return(false);
                }
            }

            Material[] mats = MB_Utility.GetGOMaterials(go);
            if (mats.Length == 0)
            {
                Debug.LogError("Object " + go + " in the list of objects to be combined does not have a material");
                return(false);
            }
            Mesh m = MB_Utility.GetMesh(go);
            if (m == null)
            {
                Debug.LogError("Object " + go + " in the list of objects to be combined does not have a mesh");
                return(false);
            }
            if (m != null)              //This check can be very expensive and it only warns so only do this if we are in the editor.
            {
                if (!Application.isEditor &&
                    Application.isPlaying &&
                    mom.textureBakeResults.doMultiMaterial &&
                    validationLevel >= MB2_ValidationLevel.robust)
                {
                    MB_Utility.MeshAnalysisResult mar;
                    if (!meshAnalysisResultCache.TryGetValue(m.GetInstanceID(), out mar))
                    {
                        MB_Utility.doSubmeshesShareVertsOrTris(m, ref mar);
                        meshAnalysisResultCache.Add(m.GetInstanceID(), mar);
                    }
                    if (mar.hasOverlappingSubmeshVerts)
                    {
                        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.");
                    }
                }
            }

            if (MBVersion.IsUsingAddressables())
            {
                HashSet <string> materialsWithDuplicateNames = new HashSet <string>();
                for (int matIdx = 0; matIdx < mats.Length; matIdx++)
                {
                    if (mats[matIdx] != null)
                    {
                        if (matName2Mat.ContainsKey(mats[matIdx].name))
                        {
                            if (mats[matIdx] != matName2Mat[mats[matIdx].name])
                            {
                                // This is an error. If using addressables we consider materials that have the same name to be the same material when baking at runtime.
                                // Two different material must NOT have the same name.
                                materialsWithDuplicateNames.Add(mats[matIdx].name);
                            }
                        }
                        else
                        {
                            matName2Mat.Add(mats[matIdx].name, mats[matIdx]);
                        }
                    }
                }

                if (materialsWithDuplicateNames.Count > 0)
                {
                    String[] stringArray = new String[materialsWithDuplicateNames.Count];
                    materialsWithDuplicateNames.CopyTo(stringArray);
                    string matsWithSameName = string.Join(",", stringArray);
                    Debug.LogError("The source objects use different materials that have the same name (" + matsWithSameName + "). " +
                                   "If using addressables, materials with the same name are considered to be the same material when baking meshes at runtime. " +
                                   "If you want to use this Material Bake Result at runtime then all source materials must have distinct names. Baking in edit-mode will still work.");
                }
            }
        }


        List <GameObject> objs = objsToMesh;

        if (mom is MB3_MeshBaker)
        {
            objs = mom.GetObjectsToCombine();
            //if (((MB3_MeshBaker)mom).useObjsToMeshFromTexBaker && tb != null) objs = tb.GetObjectsToCombine();
            if (objs == null || objs.Count == 0)
            {
                Debug.LogError("No meshes to combine. Please assign some meshes to combine.");
                return(false);
            }
            if (mom is MB3_MeshBaker && ((MB3_MeshBaker)mom).meshCombiner.settings.renderType == MB_RenderType.skinnedMeshRenderer)
            {
                if (!editorMethods.ValidateSkinnedMeshes(objs))
                {
                    return(false);
                }
            }
        }

        if (editorMethods != null)
        {
            editorMethods.CheckPrefabTypes(objToCombineType, objsToMesh);
        }
        return(true);
    }