No Description
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.

TextureGeneratorHelper.cs 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. using System;
  2. using Unity.Collections;
  3. using UnityEditor.AssetImporters;
  4. using UnityEngine;
  5. namespace UnityEditor.U2D.Common
  6. {
  7. internal interface ITextureSettings
  8. {
  9. void FillTextureGenerationSettings(ref TextureGenerationSettings settings);
  10. }
  11. [Serializable]
  12. internal class TextureSettings : ITextureSettings
  13. {
  14. [SerializeField]
  15. bool m_ColorTexture;
  16. [SerializeField]
  17. bool m_Readable;
  18. [SerializeField]
  19. TextureImporterNPOTScale m_NPOTScale;
  20. [SerializeField]
  21. FilterMode m_FilterMode;
  22. [SerializeField]
  23. int m_Aniso;
  24. [SerializeField]
  25. bool m_EnablePostProcessor;
  26. [SerializeField]
  27. SecondarySpriteTexture[] m_SecondaryTextures;
  28. public TextureSettings()
  29. {
  30. colorTexture = true;
  31. readable = false;
  32. npotScale = TextureImporterNPOTScale.None;
  33. filterMode = FilterMode.Bilinear;
  34. aniso = 1;
  35. }
  36. public TextureSettings(string assetPath, bool enablePostProcessor, bool colorTexture, bool readable, TextureImporterNPOTScale npotScale, FilterMode filterMode, int aniso, bool sourceContainsAlpha, bool sourceWasHDR)
  37. {
  38. this.assetPath = assetPath;
  39. this.enablePostProcessor = enablePostProcessor;
  40. this.colorTexture = colorTexture;
  41. this.readable = readable;
  42. this.npotScale = npotScale;
  43. this.filterMode = filterMode;
  44. this.aniso = aniso;
  45. this.containsAlpha = sourceContainsAlpha;
  46. this.hdr = sourceWasHDR;
  47. }
  48. public bool colorTexture { get { return m_ColorTexture; } set { m_ColorTexture = value; } } //sRGBTexture
  49. public bool readable { get { return m_Readable; } set { m_Readable = value; } }
  50. public TextureImporterNPOTScale npotScale { get { return m_NPOTScale; } set { m_NPOTScale = value; } }
  51. public FilterMode filterMode { get { return m_FilterMode; } set { m_FilterMode = value; } }
  52. public int aniso
  53. {
  54. get { return m_Aniso; }
  55. set { m_Aniso = value; }
  56. }
  57. public bool enablePostProcessor
  58. {
  59. get { return m_EnablePostProcessor; }
  60. set { m_EnablePostProcessor = value; }
  61. }
  62. public string assetPath { get; set; }
  63. public bool containsAlpha { get; set; }
  64. public bool hdr { get; set; }
  65. public SecondarySpriteTexture[] secondaryTextures { get { return m_SecondaryTextures;} set { m_SecondaryTextures = value; } }
  66. void ITextureSettings.FillTextureGenerationSettings(ref TextureGenerationSettings settings)
  67. {
  68. settings.textureImporterSettings.sRGBTexture = colorTexture;
  69. settings.textureImporterSettings.readable = readable;
  70. settings.textureImporterSettings.npotScale = npotScale;
  71. settings.textureImporterSettings.filterMode = filterMode;
  72. settings.textureImporterSettings.aniso = aniso;
  73. settings.assetPath = assetPath;
  74. settings.enablePostProcessor = enablePostProcessor;
  75. settings.sourceTextureInformation.containsAlpha = containsAlpha;
  76. settings.sourceTextureInformation.hdr = hdr;
  77. settings.secondarySpriteTextures = secondaryTextures;
  78. }
  79. }
  80. [Serializable]
  81. internal class TextureSpriteSettings : ITextureSettings
  82. {
  83. [SerializeField]
  84. string m_PackingTag;
  85. public string packingTag
  86. {
  87. get { return m_PackingTag; }
  88. set { m_PackingTag = value; }
  89. }
  90. [SerializeField]
  91. float m_PixelsPerUnit;
  92. public float pixelsPerUnit
  93. {
  94. get { return m_PixelsPerUnit; }
  95. set { m_PixelsPerUnit = value; }
  96. }
  97. [SerializeField]
  98. SpriteMeshType m_MeshType;
  99. public SpriteMeshType meshType
  100. {
  101. get { return m_MeshType; }
  102. set { m_MeshType = value; }
  103. }
  104. [SerializeField]
  105. uint m_ExtrudeEdges;
  106. public uint extrudeEdges
  107. {
  108. get { return m_ExtrudeEdges; }
  109. set { m_ExtrudeEdges = value; }
  110. }
  111. public bool qualifyForPacking { get; set; }
  112. public SpriteImportData[] spriteSheetData { get; set; }
  113. public TextureSpriteSettings()
  114. {
  115. packingTag = "";
  116. pixelsPerUnit = 100;
  117. meshType = SpriteMeshType.Tight;
  118. extrudeEdges = 1;
  119. }
  120. public TextureSpriteSettings(string packingTag, int pixelsPerUnit, SpriteMeshType meshType, uint extrudeEdges, bool qualifyForPacking, SpriteImportData[] spriteSheetData = null)
  121. {
  122. this.packingTag = packingTag;
  123. this.pixelsPerUnit = pixelsPerUnit;
  124. this.meshType = meshType;
  125. this.extrudeEdges = extrudeEdges;
  126. this.qualifyForPacking = qualifyForPacking;
  127. this.spriteSheetData = spriteSheetData;
  128. }
  129. void ITextureSettings.FillTextureGenerationSettings(ref TextureGenerationSettings settings)
  130. {
  131. settings.textureImporterSettings.spritePixelsPerUnit = pixelsPerUnit;
  132. settings.textureImporterSettings.spriteMeshType = meshType;
  133. settings.textureImporterSettings.spriteExtrude = extrudeEdges;
  134. settings.spritePackingTag = packingTag;
  135. settings.qualifyForSpritePacking = qualifyForPacking;
  136. settings.spriteImportData = spriteSheetData;
  137. }
  138. }
  139. [Serializable]
  140. internal class TextureWrapSettings : ITextureSettings
  141. {
  142. [SerializeField]
  143. TextureWrapMode m_WrapMode;
  144. [SerializeField]
  145. TextureWrapMode m_WrapModeU;
  146. [SerializeField]
  147. TextureWrapMode m_WrapModeV;
  148. [SerializeField]
  149. TextureWrapMode m_WrapModeW;
  150. public TextureWrapSettings()
  151. {
  152. wrapMode = wrapModeU = wrapModeV = wrapModeW = TextureWrapMode.Repeat;
  153. }
  154. public TextureWrapSettings(TextureWrapMode wrapMpde, TextureWrapMode wrapModeU, TextureWrapMode wrapModeV, TextureWrapMode wrapModeW)
  155. {
  156. this.wrapMode = wrapMode;
  157. this.wrapModeU = wrapModeU;
  158. this.wrapModeV = wrapModeV;
  159. this.wrapModeW = wrapModeW;
  160. }
  161. public TextureWrapMode wrapMode { get { return m_WrapMode; } set { m_WrapMode = value; } }
  162. public TextureWrapMode wrapModeU { get { return m_WrapModeU; } set { m_WrapModeU = value; } }
  163. public TextureWrapMode wrapModeV { get { return m_WrapModeV; } set { m_WrapModeV = value; } }
  164. public TextureWrapMode wrapModeW { get { return m_WrapModeW; } set { m_WrapModeW = value; } }
  165. void ITextureSettings.FillTextureGenerationSettings(ref TextureGenerationSettings settings)
  166. {
  167. settings.textureImporterSettings.wrapMode = wrapMode;
  168. settings.textureImporterSettings.wrapModeU = wrapModeU;
  169. settings.textureImporterSettings.wrapModeV = wrapModeV;
  170. settings.textureImporterSettings.wrapModeW = wrapModeW;
  171. }
  172. }
  173. [Serializable]
  174. internal class TextureAlphaSettings : ITextureSettings
  175. {
  176. [SerializeField]
  177. float m_AlphaTolerance;
  178. public float alphaTolerance
  179. {
  180. get { return m_AlphaTolerance; }
  181. set { m_AlphaTolerance = value; }
  182. }
  183. [SerializeField]
  184. TextureImporterAlphaSource m_AlphaSource;
  185. public TextureImporterAlphaSource alphaSource
  186. {
  187. get { return m_AlphaSource; }
  188. set { m_AlphaSource = value; }
  189. }
  190. public TextureAlphaSettings()
  191. {
  192. alphaTolerance = 0.5f;
  193. alphaSource = TextureImporterAlphaSource.FromInput;
  194. }
  195. public TextureAlphaSettings(TextureImporterAlphaSource alphaSource, float alphaTolerance)
  196. {
  197. this.alphaTolerance = alphaTolerance;
  198. this.alphaSource = alphaSource;
  199. }
  200. void ITextureSettings.FillTextureGenerationSettings(ref TextureGenerationSettings settings)
  201. {
  202. settings.textureImporterSettings.alphaIsTransparency = alphaSource != TextureImporterAlphaSource.None;
  203. settings.textureImporterSettings.alphaSource = alphaSource;
  204. settings.textureImporterSettings.alphaTestReferenceValue = alphaTolerance;
  205. }
  206. }
  207. [Serializable]
  208. internal class TextureMipmapSettings : ITextureSettings
  209. {
  210. [SerializeField]
  211. TextureImporterMipFilter m_Filter;
  212. public TextureImporterMipFilter filter
  213. {
  214. get { return m_Filter; }
  215. set { m_Filter = value; }
  216. }
  217. [SerializeField]
  218. bool m_BorderMipmap;
  219. public bool borderMipmap
  220. {
  221. get { return m_BorderMipmap; }
  222. set { m_BorderMipmap = value; }
  223. }
  224. [SerializeField]
  225. bool m_Fadeout;
  226. public bool fadeout
  227. {
  228. get { return m_Fadeout; }
  229. set { m_Fadeout = value; }
  230. }
  231. [SerializeField]
  232. bool m_PreserveCoverage;
  233. public bool preserveCoverage
  234. {
  235. get { return m_PreserveCoverage; }
  236. set { m_PreserveCoverage = value; }
  237. }
  238. [SerializeField]
  239. int m_FadeDistanceStart;
  240. public int fadeDistanceStart
  241. {
  242. get { return m_FadeDistanceStart; }
  243. set { m_FadeDistanceStart = value; }
  244. }
  245. [SerializeField]
  246. int m_FadeDistanceEnd;
  247. public int fadeDistanceEnd
  248. {
  249. get { return m_FadeDistanceEnd; }
  250. set { m_FadeDistanceEnd = value; }
  251. }
  252. public TextureMipmapSettings()
  253. {
  254. filter = TextureImporterMipFilter.BoxFilter;
  255. borderMipmap = false;
  256. fadeout = false;
  257. preserveCoverage = false;
  258. fadeDistanceStart = 1;
  259. fadeDistanceEnd = 3;
  260. }
  261. public TextureMipmapSettings(TextureImporterMipFilter filter, bool borderMipmap, bool fadeout, bool preserveCoverage, int fadeDistanceStart, int fadeDistanceEnd)
  262. {
  263. this.filter = filter;
  264. this.borderMipmap = borderMipmap;
  265. this.fadeout = fadeout;
  266. this.preserveCoverage = preserveCoverage;
  267. this.fadeDistanceStart = fadeDistanceStart;
  268. this.fadeDistanceEnd = fadeDistanceEnd;
  269. }
  270. void ITextureSettings.FillTextureGenerationSettings(ref TextureGenerationSettings settings)
  271. {
  272. settings.textureImporterSettings.mipmapEnabled = true;
  273. settings.textureImporterSettings.mipmapFilter = filter;
  274. settings.textureImporterSettings.borderMipmap = borderMipmap;
  275. settings.textureImporterSettings.fadeOut = fadeout;
  276. settings.textureImporterSettings.mipmapFadeDistanceStart = fadeDistanceStart;
  277. settings.textureImporterSettings.mipmapFadeDistanceEnd = fadeDistanceEnd;
  278. settings.textureImporterSettings.mipMapsPreserveCoverage = preserveCoverage;
  279. }
  280. }
  281. [Serializable]
  282. internal class TextureNormalSettings : ITextureSettings
  283. {
  284. [SerializeField]
  285. TextureImporterNormalFilter m_Filter;
  286. public TextureImporterNormalFilter filter
  287. {
  288. get { return m_Filter; }
  289. set { m_Filter = value; }
  290. }
  291. [SerializeField]
  292. bool m_GenerateFromGrayScale;
  293. public bool generateFromGrayScale
  294. {
  295. get { return m_GenerateFromGrayScale; }
  296. set { m_GenerateFromGrayScale = value; }
  297. }
  298. [SerializeField]
  299. float m_Bumpiness;
  300. public float bumpiness
  301. {
  302. get { return m_Bumpiness; }
  303. set { m_Bumpiness = value; }
  304. }
  305. public TextureNormalSettings()
  306. {
  307. filter = TextureImporterNormalFilter.Standard;
  308. generateFromGrayScale = false;
  309. bumpiness = 0.25f;
  310. }
  311. public TextureNormalSettings(TextureImporterNormalFilter filter, bool generateFromGrayScale, float bumpiness)
  312. {
  313. this.filter = filter;
  314. this.generateFromGrayScale = generateFromGrayScale;
  315. this.bumpiness = bumpiness;
  316. }
  317. void ITextureSettings.FillTextureGenerationSettings(ref TextureGenerationSettings settings)
  318. {
  319. settings.textureImporterSettings.normalMapFilter = filter;
  320. settings.textureImporterSettings.convertToNormalMap = generateFromGrayScale;
  321. settings.textureImporterSettings.heightmapScale = bumpiness;
  322. }
  323. }
  324. // If this is provided, textureType will be cubemap
  325. [Serializable]
  326. internal class TextureCubemapSettings : ITextureSettings
  327. {
  328. [SerializeField]
  329. TextureImporterCubemapConvolution m_Convolution;
  330. public TextureImporterCubemapConvolution convolution
  331. {
  332. get { return m_Convolution; }
  333. set { m_Convolution = value; }
  334. }
  335. [SerializeField]
  336. TextureImporterGenerateCubemap m_Mode;
  337. public TextureImporterGenerateCubemap mode
  338. {
  339. get { return m_Mode; }
  340. set { m_Mode = value; }
  341. }
  342. [SerializeField]
  343. bool m_Seamless;
  344. public bool seamless
  345. {
  346. get { return m_Seamless; }
  347. set { m_Seamless = value; }
  348. }
  349. public TextureCubemapSettings()
  350. {
  351. convolution = TextureImporterCubemapConvolution.None;
  352. mode = TextureImporterGenerateCubemap.AutoCubemap;
  353. seamless = false;
  354. }
  355. public TextureCubemapSettings(TextureImporterCubemapConvolution convolution, TextureImporterGenerateCubemap mode, bool seamless)
  356. {
  357. this.convolution = convolution;
  358. this.mode = mode;
  359. this.seamless = seamless;
  360. }
  361. void ITextureSettings.FillTextureGenerationSettings(ref TextureGenerationSettings settings)
  362. {
  363. settings.textureImporterSettings.textureShape = TextureImporterShape.TextureCube;
  364. settings.textureImporterSettings.cubemapConvolution = convolution;
  365. settings.textureImporterSettings.generateCubemap = mode;
  366. settings.textureImporterSettings.seamlessCubemap = seamless;
  367. }
  368. }
  369. internal static class TextureGeneratorHelper
  370. {
  371. public static TextureGenerationOutput GenerateTextureSprite(NativeArray<Color32> buffer, int bufferWidth, int bufferHeight, TextureSettings settings, TextureImporterPlatformSettings platformSettings,
  372. TextureSpriteSettings spriteSettings, TextureAlphaSettings alphaSettings = null, TextureMipmapSettings mipmapSettings = null, TextureWrapSettings wrapSettings = null)
  373. {
  374. if (alphaSettings == null)
  375. alphaSettings = new TextureAlphaSettings(TextureImporterAlphaSource.FromInput, 0.5f);
  376. if (wrapSettings == null)
  377. wrapSettings = new TextureWrapSettings(TextureWrapMode.Clamp, TextureWrapMode.Clamp, TextureWrapMode.Clamp, TextureWrapMode.Clamp);
  378. return GenerateTexture(buffer, bufferWidth, bufferHeight, TextureImporterType.Sprite, platformSettings, settings, spriteSettings, alphaSettings, mipmapSettings, wrapSettings);
  379. }
  380. public static TextureGenerationOutput GenerateLightmap(NativeArray<Color32> buffer, int bufferWidth, int bufferHeight, TextureSettings settings, TextureImporterPlatformSettings platformSettings,
  381. TextureMipmapSettings mipmapSettings = null, TextureWrapSettings wrapSettings = null)
  382. {
  383. settings.colorTexture = true;
  384. return GenerateTexture(buffer, bufferWidth, bufferHeight, TextureImporterType.Lightmap, platformSettings, settings, mipmapSettings, wrapSettings);
  385. }
  386. public static TextureGenerationOutput GenerateCookie(NativeArray<Color32> buffer, int bufferWidth, int bufferHeight, TextureSettings settings, TextureImporterPlatformSettings platformSettings,
  387. TextureAlphaSettings alphaSettings = null, TextureMipmapSettings mipmapSettings = null, TextureCubemapSettings cubemapSettings = null, TextureWrapSettings wrapSettings = null)
  388. {
  389. return GenerateTexture(buffer, bufferWidth, bufferHeight, TextureImporterType.Cookie, platformSettings, settings, alphaSettings, mipmapSettings, cubemapSettings, wrapSettings);
  390. }
  391. public static TextureGenerationOutput GenerateNormalMap(NativeArray<Color32> buffer, int bufferWidth, int bufferHeight, TextureSettings settings, TextureImporterPlatformSettings platformSettings,
  392. TextureNormalSettings normalSettings, TextureMipmapSettings mipmapSettings = null, TextureCubemapSettings cubemapSettings = null, TextureWrapSettings wrapSettings = null)
  393. {
  394. settings.colorTexture = false;
  395. return GenerateTexture(buffer, bufferWidth, bufferHeight, TextureImporterType.NormalMap, platformSettings, settings, normalSettings, mipmapSettings, cubemapSettings, wrapSettings);
  396. }
  397. public static TextureGenerationOutput GenerateTextureGUI(NativeArray<Color32> buffer, int bufferWidth, int bufferHeight, TextureSettings settings, TextureImporterPlatformSettings platformSettings,
  398. TextureAlphaSettings alphaSettings = null, TextureMipmapSettings mipmapSettings = null, TextureWrapSettings wrapSettings = null)
  399. {
  400. settings.colorTexture = false;
  401. if (wrapSettings == null)
  402. wrapSettings = new TextureWrapSettings(TextureWrapMode.Clamp, TextureWrapMode.Clamp, TextureWrapMode.Clamp, TextureWrapMode.Clamp);
  403. return GenerateTexture(buffer, bufferWidth, bufferHeight, TextureImporterType.GUI, platformSettings, settings, alphaSettings, mipmapSettings, wrapSettings);
  404. }
  405. public static TextureGenerationOutput GenerateTextureSingleChannel(NativeArray<Color32> buffer, int bufferWidth, int bufferHeight, TextureSettings settings, TextureImporterPlatformSettings platformSettings,
  406. TextureAlphaSettings alphaSettings = null, TextureMipmapSettings mipmapSettings = null, TextureCubemapSettings cubemapSettings = null, TextureWrapSettings wrapSettings = null)
  407. {
  408. settings.colorTexture = false;
  409. return GenerateTexture(buffer, bufferWidth, bufferHeight, TextureImporterType.SingleChannel, platformSettings, settings, alphaSettings, mipmapSettings, cubemapSettings, wrapSettings);
  410. }
  411. public static TextureGenerationOutput GenerateTextureCursor(NativeArray<Color32> buffer, int bufferWidth, int bufferHeight, TextureSettings settings, TextureImporterPlatformSettings platformSettings,
  412. TextureAlphaSettings alphaSettings = null, TextureMipmapSettings mipmapSettings = null, TextureWrapSettings wrapSettings = null)
  413. {
  414. if (alphaSettings == null)
  415. alphaSettings = new TextureAlphaSettings(TextureImporterAlphaSource.FromInput, 0.5f);
  416. if (wrapSettings == null)
  417. wrapSettings = new TextureWrapSettings(TextureWrapMode.Clamp, TextureWrapMode.Clamp, TextureWrapMode.Clamp, TextureWrapMode.Clamp);
  418. return GenerateTexture(buffer, bufferWidth, bufferHeight, TextureImporterType.Cursor, platformSettings, settings, alphaSettings, mipmapSettings, wrapSettings);
  419. }
  420. public static TextureGenerationOutput GenerateTextureDefault(NativeArray<Color32> buffer, int bufferWidth, int bufferHeight, TextureSettings settings, TextureImporterPlatformSettings platformSettings,
  421. TextureAlphaSettings alphaSettings = null, TextureMipmapSettings mipmapSettings = null, TextureCubemapSettings cubemapSettings = null, TextureWrapSettings wrapSettings = null)
  422. {
  423. if (mipmapSettings == null)
  424. mipmapSettings = new TextureMipmapSettings(TextureImporterMipFilter.BoxFilter, false, false, false, 1, 3);
  425. return GenerateTexture(buffer, bufferWidth, bufferHeight, TextureImporterType.Default, platformSettings, settings, alphaSettings, mipmapSettings, cubemapSettings, wrapSettings);
  426. }
  427. static TextureGenerationOutput GenerateTexture(NativeArray<Color32> imageBuffer, int imageBufferWidth, int imageBufferHeight, TextureImporterType type, TextureImporterPlatformSettings platformSettings, params ITextureSettings[] otherSettings)
  428. {
  429. var textureGenerationSettings = new TextureGenerationSettings();
  430. textureGenerationSettings.platformSettings = platformSettings;
  431. textureGenerationSettings.sourceTextureInformation = new SourceTextureInformation();
  432. textureGenerationSettings.sourceTextureInformation.height = imageBufferHeight;
  433. textureGenerationSettings.sourceTextureInformation.width = imageBufferWidth;
  434. textureGenerationSettings.textureImporterSettings = new TextureImporterSettings();
  435. textureGenerationSettings.textureImporterSettings.textureType = type;
  436. textureGenerationSettings.textureImporterSettings.textureShape = TextureImporterShape.Texture2D;
  437. textureGenerationSettings.textureImporterSettings.alphaIsTransparency = false;
  438. textureGenerationSettings.textureImporterSettings.convertToNormalMap = false;
  439. textureGenerationSettings.textureImporterSettings.mipmapEnabled = false;
  440. textureGenerationSettings.textureImporterSettings.sRGBTexture = true;
  441. textureGenerationSettings.textureImporterSettings.readable = false;
  442. textureGenerationSettings.textureImporterSettings.fadeOut = false;
  443. textureGenerationSettings.textureImporterSettings.wrapMode = TextureWrapMode.Repeat;
  444. textureGenerationSettings.textureImporterSettings.wrapModeU = TextureWrapMode.Repeat;
  445. textureGenerationSettings.textureImporterSettings.wrapModeV = TextureWrapMode.Repeat;
  446. textureGenerationSettings.textureImporterSettings.wrapModeW = TextureWrapMode.Repeat;
  447. foreach (var otherSetting in otherSettings)
  448. {
  449. if (otherSetting != null)
  450. otherSetting.FillTextureGenerationSettings(ref textureGenerationSettings);
  451. }
  452. return TextureGenerator.GenerateTexture(textureGenerationSettings, imageBuffer);
  453. }
  454. static public TextureSettings ExtractTextureSettings(this TextureImporterSettings tis)
  455. {
  456. var ts = new TextureSettings();
  457. ts.colorTexture = tis.sRGBTexture;
  458. ts.readable = tis.readable;
  459. ts.npotScale = tis.npotScale;
  460. ts.filterMode = tis.filterMode;
  461. ts.aniso = tis.aniso;
  462. return ts;
  463. }
  464. static public TextureSpriteSettings ExtractTextureSpriteSettings(this TextureImporterSettings tis)
  465. {
  466. var ts = new TextureSpriteSettings();
  467. ts.pixelsPerUnit = tis.spritePixelsPerUnit;
  468. ts.meshType = tis.spriteMeshType;
  469. ts.extrudeEdges = tis.spriteExtrude;
  470. return ts;
  471. }
  472. static public TextureWrapSettings ExtractTextureWrapSettings(this TextureImporterSettings tis)
  473. {
  474. var ts = new TextureWrapSettings();
  475. ts.wrapMode = tis.wrapMode;
  476. ts.wrapModeU = tis.wrapModeU;
  477. ts.wrapModeV = tis.wrapModeV;
  478. ts.wrapModeW = tis.wrapModeW;
  479. return ts;
  480. }
  481. static public TextureAlphaSettings ExtractTextureAlphaSettings(this TextureImporterSettings settings)
  482. {
  483. if (settings.alphaIsTransparency == false)
  484. return null;
  485. var ts = new TextureAlphaSettings();
  486. ts.alphaSource = settings.alphaSource;
  487. ts.alphaTolerance = settings.alphaTestReferenceValue;
  488. return ts;
  489. }
  490. static public TextureMipmapSettings ExtractTextureMipmapSettings(this TextureImporterSettings settings)
  491. {
  492. if (!settings.mipmapEnabled)
  493. return null;
  494. var ts = new TextureMipmapSettings();
  495. ts.filter = settings.mipmapFilter;
  496. ts.borderMipmap = settings.borderMipmap;
  497. ts.fadeout = settings.fadeOut;
  498. ts.fadeDistanceStart = settings.mipmapFadeDistanceStart;
  499. ts.fadeDistanceEnd = settings.mipmapFadeDistanceEnd;
  500. ts.preserveCoverage = settings.mipMapsPreserveCoverage;
  501. return ts;
  502. }
  503. static public TextureNormalSettings ExtractTextureNormalSettings(this TextureImporterSettings settings)
  504. {
  505. var ts = new TextureNormalSettings();
  506. ts.filter = settings.normalMapFilter;
  507. ts.generateFromGrayScale = settings.convertToNormalMap;
  508. ts.bumpiness = settings.heightmapScale;
  509. return ts;
  510. }
  511. static public TextureCubemapSettings ExtractTextureCubemapSettings(this TextureImporterSettings settings)
  512. {
  513. if (settings.textureShape != TextureImporterShape.TextureCube)
  514. return null;
  515. var ts = new TextureCubemapSettings();
  516. ts.convolution = settings.cubemapConvolution;
  517. ts.mode = settings.generateCubemap;
  518. ts.seamless = settings.seamlessCubemap;
  519. return ts;
  520. }
  521. }
  522. }