Skip to content

Commit

Permalink
Normal encoding dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
pfcDorn committed Jan 16, 2024
1 parent cd4975e commit c5bbd35
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Editor/Scripts/GLTFImporter.cs
Expand Up @@ -653,7 +653,7 @@ string GetUniqueName(string desiredName)
var convertedFormat = (TextureFormat)(int)format;
if ((int)convertedFormat > -1)
{
// Debug.Log("Compressing texture " + tex.name + "(format: " + tex.format + ", mips: " + tex.mipmapCount + ") to: " + convertedFormat);
//Debug.Log("Compressing texture " + tex.name + "(format: " + tex.format + ", mips: " + tex.mipmapCount + ") to: " + convertedFormat);
EditorUtility.CompressTexture(tex, convertedFormat, (TextureCompressionQuality) (int) _textureCompression);
// Debug.Log("Mips now: " + tex.mipmapCount); // TODO figure out why mipmaps disappear here
}
Expand Down Expand Up @@ -772,6 +772,7 @@ string GetUniqueName(string desiredName)

#if UNITY_2020_2_OR_NEWER
ctx.DependsOnCustomDependency(ColorSpaceDependency);
ctx.DependsOnCustomDependency(NormalMapEncodingDependency);
#endif
if (gltfScene)
{
Expand Down Expand Up @@ -804,13 +805,22 @@ string GetUniqueName(string desiredName)
}

private const string ColorSpaceDependency = nameof(GLTFImporter) + "_" + nameof(PlayerSettings.colorSpace);
private const string NormalMapEncodingDependency = nameof(GLTFImporter) + "_normalMapEncoding";

#if UNITY_2020_2_OR_NEWER
[InitializeOnLoadMethod]
private static void UpdateColorSpace()
{
AssetDatabase.RegisterCustomDependency(ColorSpaceDependency, Hash128.Compute((int) PlayerSettings.colorSpace));
}

[InitializeOnLoadMethod]
private static void UpdateNormalMapEncoding()
{
//Debug.Log("Normal map encoding changed: " + PlayerSettings.GetNormalMapEncoding(BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget))+" "+BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget));
AssetDatabase.RegisterCustomDependency(ColorSpaceDependency, Hash128.Compute((int) PlayerSettings.GetNormalMapEncoding(BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget))));
}

#endif

private void CreateGLTFScene(GLTFImportContext context, out GameObject scene,
Expand Down

0 comments on commit c5bbd35

Please sign in to comment.