MB3_TextureCombinerPackerOneTextureInAtlas.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System;
  5. namespace DigitalOpus.MB.Core
  6. {
  7. internal class MB3_TextureCombinerPackerOneTextureInAtlas : MB_ITextureCombinerPacker
  8. {
  9. public IEnumerator ConvertTexturesToReadableFormats(ProgressUpdateDelegate progressInfo,
  10. MB3_TextureCombiner.CombineTexturesIntoAtlasesCoroutineResult result,
  11. MB3_TextureCombinerPipeline.TexturePipelineData data,
  12. MB3_TextureCombiner combiner,
  13. MB2_EditorMethodsInterface textureEditorMethods,
  14. MB2_LogLevel LOG_LEVEL)
  15. {
  16. Debug.Assert(data.OnlyOneTextureInAtlasReuseTextures());
  17. yield break;
  18. }
  19. public AtlasPackingResult[] CalculateAtlasRectangles(MB3_TextureCombinerPipeline.TexturePipelineData data, bool doMultiAtlas, MB2_LogLevel LOG_LEVEL)
  20. {
  21. Debug.Assert(data.OnlyOneTextureInAtlasReuseTextures());
  22. if (LOG_LEVEL >= MB2_LogLevel.debug) Debug.Log("Only one image per atlas. Will re-use original texture");
  23. AtlasPackingResult[] packerRects = new AtlasPackingResult[1];
  24. AtlasPadding[] paddings = new AtlasPadding[] { new AtlasPadding(data._atlasPadding) };
  25. packerRects[0] = new AtlasPackingResult(paddings);
  26. packerRects[0].rects = new Rect[1];
  27. packerRects[0].srcImgIdxs = new int[] { 0 };
  28. packerRects[0].rects[0] = new Rect(0f, 0f, 1f, 1f);
  29. MeshBakerMaterialTexture dmt = null;
  30. if (data.distinctMaterialTextures[0].ts.Length > 0)
  31. {
  32. dmt = data.distinctMaterialTextures[0].ts[0];
  33. }
  34. if (dmt == null || dmt.isNull)
  35. {
  36. packerRects[0].atlasX = 16;
  37. packerRects[0].atlasY = 16;
  38. packerRects[0].usedW = 16;
  39. packerRects[0].usedH = 16;
  40. }
  41. else
  42. {
  43. packerRects[0].atlasX = dmt.width;
  44. packerRects[0].atlasY = dmt.height;
  45. packerRects[0].usedW = dmt.width;
  46. packerRects[0].usedH = dmt.height;
  47. }
  48. return packerRects;
  49. }
  50. public IEnumerator CreateAtlases(ProgressUpdateDelegate progressInfo,
  51. MB3_TextureCombinerPipeline.TexturePipelineData data, MB3_TextureCombiner combiner,
  52. AtlasPackingResult packedAtlasRects,
  53. Texture2D[] atlases, MB2_EditorMethodsInterface textureEditorMethods,
  54. MB2_LogLevel LOG_LEVEL)
  55. {
  56. Debug.Assert(data.OnlyOneTextureInAtlasReuseTextures());
  57. if (LOG_LEVEL >= MB2_LogLevel.debug) Debug.Log("Only one image per atlas. Will re-use original texture");
  58. for (int i = 0; i < data.numAtlases; i++)
  59. {
  60. MeshBakerMaterialTexture dmt = data.distinctMaterialTextures[0].ts[i];
  61. atlases[i] = dmt.GetTexture2D();
  62. if (data.resultType == MB2_TextureBakeResults.ResultType.atlas)
  63. {
  64. data.resultMaterial.SetTexture(data.texPropertyNames[i].name, atlases[i]);
  65. data.resultMaterial.SetTextureScale(data.texPropertyNames[i].name, Vector2.one);
  66. data.resultMaterial.SetTextureOffset(data.texPropertyNames[i].name, Vector2.zero);
  67. }
  68. }
  69. yield break;
  70. }
  71. }
  72. }