Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compress textures on import to platform-specific default format
- Loading branch information
1 parent
7f859e8
commit 877b73b
Showing
6 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
135 changes: 135 additions & 0 deletions
135
Editor/Scripts/Internal/DefaultImportSettings/DefaultTexture.png.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using System.Reflection; | ||
using UnityEditor; | ||
using UnityEditor.Build; | ||
using UnityEngine; | ||
|
||
namespace UnityGLTF | ||
{ | ||
public class TextureImporterHelper | ||
{ | ||
private static MethodInfo GetFixedPlatformName; | ||
private const string DefaultTextureAssetGuid = "7b7ff3cec11c24c599d6f12443877d5e"; | ||
|
||
public static TextureImporterFormat GetAutomaticFormat(Texture2D texture, string platform) | ||
{ | ||
var defaultTextureImporter = AssetImporter.GetAtPath(AssetDatabase.GUIDToAssetPath(DefaultTextureAssetGuid)) as TextureImporter; | ||
// defaultTextureImporter = new TextureImporter(); | ||
|
||
if (GetFixedPlatformName == null) | ||
GetFixedPlatformName = typeof(TextureImporter) | ||
.GetMethod("GetFixedPlatformName", BindingFlags.Static | BindingFlags.NonPublic); | ||
|
||
if (GetFixedPlatformName == null) | ||
throw new MissingMethodException("TextureImporter.GetFixedPlatformName"); | ||
|
||
platform = GetFixedPlatformName.Invoke(null, new object[] { platform }) as string; | ||
TextureImporterSettings importerSettings = new TextureImporterSettings(); | ||
|
||
importerSettings.aniso = 5; | ||
importerSettings.wrapMode = texture.wrapMode; | ||
importerSettings.filterMode = texture.filterMode; | ||
importerSettings.mipmapEnabled = texture.mipmapCount > 1; | ||
importerSettings.alphaSource = TextureImporterAlphaSource.FromInput; | ||
|
||
var hasAlpha = TextureUtil.HasAlphaTextureFormat(texture.format); | ||
var isHDR = TextureUtil.IsHDRFormat(texture.format); | ||
|
||
// var platformSettings = new TextureImporterPlatformSettings(); | ||
|
||
foreach (BuildPlatform validPlatform in BuildPlatforms.instance.GetValidPlatforms()) | ||
{ | ||
// TextureImporter.RecommendedFormatsFromTextureTypeAndPlatform | ||
if (validPlatform.name == platform) | ||
return TextureImporter.DefaultFormatFromTextureParameters(importerSettings, defaultTextureImporter.GetPlatformTextureSettings(platform), hasAlpha, isHDR, validPlatform.defaultTarget); | ||
} | ||
|
||
// This should never happen | ||
return TextureImporterFormat.Automatic; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.