public override void DestroyMeshEditor(SA2EditorMethodsInterface editorMethods) { for (int i = 0; i < meshCombiners.Count; i++) { if (meshCombiners[i].combinedMesh.targetRenderer != null) { editorMethods.Destroy(meshCombiners[i].combinedMesh.targetRenderer.gameObject); } meshCombiners[i].combinedMesh.ClearMesh(); } obj2MeshCombinerMap.Clear(); meshCombiners.Clear(); }
public static bool DoCombinedValidate(SA3MeshCombineRoot mom, SAObjsToCombineTypes objToCombineType, SA2EditorMethodsInterface editorMethods) { if (mom.textureBakeResults == null) { Debug.LogError("Need to set Material Bake Result on " + mom); return(false); } if (!(mom is SA3TextureCombine)) { SA3TextureCombine tb = mom.GetComponent <SA3TextureCombine>(); 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 SA3TextureCombine."); } } 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 (SAUtility.GetGOMaterials(go) == null) { Debug.LogError("Object " + go + " in the list of objects to be combined does not have a material"); return(false); } if (SAUtility.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 SA3MeshCombine) { objs = mom.GetObjectsToCombine(); //if (((SA3MeshCombine)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 SA3MeshCombine && ((SA3MeshCombine)mom).meshCombiner.renderType == SARenderType.skinnedMeshRenderer) { if (!editorMethods.ValidateSkinnedMeshes(objs)) { return(false); } } } if (editorMethods != null) { editorMethods.CheckPrefabTypes(objToCombineType, objsToMesh); } return(true); }
public virtual void DestroyMeshEditor(SA2EditorMethodsInterface editorMethods) { meshCombiner.DestroyMeshEditor(editorMethods); }
SAAtlasesAndRects[] _CreateAtlases(ProgressUpdateDelegate progressInfo, bool saveAtlasesAsAssets = false, SA2EditorMethodsInterface editorMethods = null) { //validation if (saveAtlasesAsAssets && editorMethods == null) { Debug.LogError("Error in CreateAtlases If saveAtlasesAsAssets = true then editorMethods cannot be null."); return(null); } if (saveAtlasesAsAssets && !Application.isEditor) { Debug.LogError("Error in CreateAtlases If saveAtlasesAsAssets = true it must be called from the Unity Editor."); return(null); } if (!DoCombinedValidate(this, SAObjsToCombineTypes.dontCare, editorMethods)) { return(null); } if (_doMultiMaterial && !_ValidateResultMaterials()) { return(null); } else if (!_doMultiMaterial) { if (_resultMaterial == null) { Debug.LogError("Combined Material is null please create and assign a result material."); return(null); } Shader targShader = _resultMaterial.shader; for (int i = 0; i < objsToMesh.Count; i++) { Material[] ms = SAUtility.GetGOMaterials(objsToMesh[i]); for (int j = 0; j < ms.Length; j++) { Material m = ms[j]; if (m == null) { Debug.LogError("Game object " + objsToMesh[i] + " has a null material. Can't build atlases"); return(null); } else if (m != null && m.shader != targShader) { Debug.LogWarning("Game object " + objsToMesh[i] + " does not use shader " + targShader + " it may not have the required textures. If not 2x2 clear textures will be generated."); } } } } //for (int i = 0; i < objsToMesh.Count; i++) //{ // Material[] ms = SAUtility.GetGOMaterials(objsToMesh[i]); // for (int j = 0; j < ms.Length; j++) // { // Material m = ms[j]; // if (m == null) // { // Debug.LogError("Game object " + objsToMesh[i] + " has a null material. Can't build atlases"); // return null; // } // } //} SA3TextureCombiner combiner = new SA3TextureCombiner(); combiner.LOG_LEVEL = LOG_LEVEL; combiner.atlasPadding = _atlasPadding; combiner.customShaderPropNames = _customShaderPropNames; combiner.fixOutOfBoundsUVs = _fixOutOfBoundsUVs; combiner.maxTilingBakeSize = _maxTilingBakeSize; combiner.packingAlgorithm = _packingAlgorithm; combiner.combineTexturePackerForcePowerOfTwo = _combineTexturePackerForcePowerOfTwo; combiner.resizePowerOfTwoTextures = _resizePowerOfTwoTextures; combiner.saveAtlasesAsAssets = saveAtlasesAsAssets; // if editor analyse meshes and suggest treatment if (!Application.isPlaying) { Material[] rms; if (_doMultiMaterial) { rms = new Material[resultMaterials.Length]; for (int i = 0; i < rms.Length; i++) { rms[i] = resultMaterials[i].combinedMaterial; } } else { rms = new Material[1]; rms[0] = _resultMaterial; } combiner.SuggestTreatment(objsToMesh, rms, combiner.customShaderPropNames); } //initialize structure to store results int numResults = 1; if (_doMultiMaterial) { numResults = resultMaterials.Length; } SAAtlasesAndRects[] resultAtlasesAndRects = new SAAtlasesAndRects[numResults]; for (int i = 0; i < resultAtlasesAndRects.Length; i++) { resultAtlasesAndRects[i] = new SAAtlasesAndRects(); } //Do the material combining. for (int i = 0; i < resultAtlasesAndRects.Length; i++) { Material resMatToPass = null; List <Material> sourceMats = null; if (_doMultiMaterial) { sourceMats = resultMaterials[i].sourceMaterials; resMatToPass = resultMaterials[i].combinedMaterial; } else { resMatToPass = _resultMaterial; } Debug.Log("Creating atlases for result material " + resMatToPass); if (!combiner.CombineTexturesIntoAtlases(progressInfo, resultAtlasesAndRects[i], resMatToPass, objsToMesh, sourceMats, editorMethods)) { return(null); } } //Save the results textureBakeResults.combinedMaterialInfo = resultAtlasesAndRects; textureBakeResults.doMultiMaterial = _doMultiMaterial; textureBakeResults.resultMaterial = _resultMaterial; textureBakeResults.resultMaterials = resultMaterials; textureBakeResults.fixOutOfBoundsUVs = combiner.fixOutOfBoundsUVs; unpackMat2RectMap(textureBakeResults); //set the texture bake resultAtlasesAndRects on the Mesh Baker component if it exists SA3MeshCombineCommon[] mb = GetComponentsInChildren <SA3MeshCombineCommon>(); for (int i = 0; i < mb.Length; i++) { mb[i].textureBakeResults = textureBakeResults; } if (LOG_LEVEL >= SA2LogLevel.info) { Debug.Log("Created Atlases"); } return(resultAtlasesAndRects); }
/// <summary> /// Creates the atlases. /// </summary> /// <returns> /// The atlases. /// </returns> /// <param name='progressInfo'> /// Progress info is a delegate function that displays a progress dialog. Can be null /// </param> /// <param name='saveAtlasesAsAssets'> /// if true atlases are saved as assets in the project folder. Othersise they are instances in memory /// </param> /// <param name='editorMethods'> /// Texture format tracker. Contains editor functionality such as save assets. Can be null. /// </param> public SAAtlasesAndRects[] CreateAtlases(ProgressUpdateDelegate progressInfo, bool saveAtlasesAsAssets = false, SA2EditorMethodsInterface editorMethods = null) { SAAtlasesAndRects[] mAndAs = null; try { mAndAs = _CreateAtlases(progressInfo, saveAtlasesAsAssets, editorMethods); } catch (Exception e) { Debug.LogError(e); } finally { if (saveAtlasesAsAssets) { //Atlases were saved to project so we don't need these ones if (mAndAs != null) { for (int j = 0; j < mAndAs.Length; j++) { SAAtlasesAndRects mAndA = mAndAs[j]; if (mAndA != null && mAndA.atlases != null) { for (int i = 0; i < mAndA.atlases.Length; i++) { if (mAndA.atlases[i] != null) { if (editorMethods != null) { editorMethods.Destroy(mAndA.atlases[i]); } else { SAUtility.Destroy(mAndA.atlases[i]); } } } } } } } } return(mAndAs); }
public abstract void DestroyMeshEditor(SA2EditorMethodsInterface editorMethods);