源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
4.2 KiB

преди 1 месец
  1. //----------------------------------------------
  2. // MeshBaker
  3. // Copyright © 2011-2012 Ian Deane
  4. //----------------------------------------------
  5. using UnityEngine;
  6. using System.Collections;
  7. using System.Collections.Specialized;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Text;
  11. using DigitalOpus.MB.Core;
  12. using LuaFramework;
  13. /// <summary>
  14. /// Root class of all the baking Components
  15. /// </summary>
  16. public abstract class MB3_MeshBakerRoot : MonoBehaviour {
  17. [HideInInspector] public abstract MB2_TextureBakeResults textureBakeResults{
  18. get;
  19. set;
  20. }
  21. //todo switch this to List<Renderer>
  22. public virtual List<GameObject> GetObjectsToCombine(){
  23. return null;
  24. }
  25. public static bool DoCombinedValidate(MB3_MeshBakerRoot mom, MB_ObjsToCombineTypes objToCombineType, MB2_EditorMethodsInterface editorMethods, MB2_ValidationLevel validationLevel){
  26. if (mom.textureBakeResults == null){
  27. LogManager.LogError("Need to set Material Bake Result on " + mom);
  28. return false;
  29. }
  30. if (mom is MB3_MeshBakerCommon){
  31. MB3_MeshBakerCommon momMB = (MB3_MeshBakerCommon) mom;
  32. MB3_TextureBaker tb = momMB.GetTextureBaker();
  33. if (tb != null && tb.textureBakeResults != mom.textureBakeResults){
  34. LogManager.LogWarning("Material Bake Result on this component is not the same as the Material Bake Result on the MB3_TextureBaker.");
  35. }
  36. }
  37. Dictionary<int,MB_Utility.MeshAnalysisResult> meshAnalysisResultCache = null;
  38. if (validationLevel == MB2_ValidationLevel.robust){
  39. meshAnalysisResultCache = new Dictionary<int, MB_Utility.MeshAnalysisResult>();
  40. }
  41. List<GameObject> objsToMesh = mom.GetObjectsToCombine();
  42. for (int i = 0; i < objsToMesh.Count; i++){
  43. GameObject go = objsToMesh[i];
  44. if (go == null){
  45. LogManager.LogError("The list of objects to combine contains a null at position." + i + " Select and use [shift] delete to remove");
  46. return false;
  47. }
  48. for (int j = i + 1; j < objsToMesh.Count; j++){
  49. if (objsToMesh[i] == objsToMesh[j]){
  50. LogManager.LogError("The list of objects to combine contains duplicates at " + i + " and " + j);
  51. return false;
  52. }
  53. }
  54. if (MB_Utility.GetGOMaterials(go) == null){
  55. LogManager.LogError("Object " + go + " in the list of objects to be combined does not have a material");
  56. return false;
  57. }
  58. Mesh m = MB_Utility.GetMesh(go);
  59. if (m == null){
  60. LogManager.LogError("Object " + go + " in the list of objects to be combined does not have a mesh");
  61. return false;
  62. }
  63. if (m != null){ //This check can be very expensive and it only warns so only do this if we are in the editor.
  64. if (!Application.isEditor &&
  65. Application.isPlaying &&
  66. mom.textureBakeResults.doMultiMaterial &&
  67. validationLevel >= MB2_ValidationLevel.robust){
  68. MB_Utility.MeshAnalysisResult mar;
  69. if (!meshAnalysisResultCache.TryGetValue(m.GetInstanceID(),out mar)){
  70. MB_Utility.doSubmeshesShareVertsOrTris(m,ref mar);
  71. meshAnalysisResultCache.Add (m.GetInstanceID(),mar);
  72. }
  73. if (mar.hasOverlappingSubmeshVerts){
  74. LogManager.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.");
  75. }
  76. }
  77. }
  78. }
  79. List<GameObject> objs = objsToMesh;
  80. if (mom is MB3_MeshBaker)
  81. {
  82. objs = mom.GetObjectsToCombine();
  83. //if (((MB3_MeshBaker)mom).useObjsToMeshFromTexBaker && tb != null) objs = tb.GetObjectsToCombine();
  84. if (objs == null || objs.Count == 0)
  85. {
  86. LogManager.LogError("No meshes to combine. Please assign some meshes to combine.");
  87. return false;
  88. }
  89. if (mom is MB3_MeshBaker && ((MB3_MeshBaker)mom).meshCombiner.renderType == MB_RenderType.skinnedMeshRenderer){
  90. if (!editorMethods.ValidateSkinnedMeshes(objs))
  91. {
  92. return false;
  93. }
  94. }
  95. }
  96. if (editorMethods != null){
  97. editorMethods.CheckPrefabTypes(objToCombineType, objsToMesh);
  98. }
  99. return true;
  100. }
  101. }