Skip to content

Commit

Permalink
Add menu item to open cache directory, add option to settings to disa…
Browse files Browse the repository at this point in the history
…ble caching
  • Loading branch information
marwie committed Jan 4, 2023
1 parent efd5f5a commit a7a5dd4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ private static void Init()
// Keep some files in cache that were last exported
EditorApplication.quitting += () => Shrink(200);
}

[MenuItem("Edit/UnityGLTF/Open Cache Directory")]
private static void OpenCacheDirectory()
{
var dir = CacheDirectory;
if(Directory.Exists(dir)) EditorUtility.RevealInFinder(dir);
else Debug.LogWarning($"Cache directory does not exist: {dir}");
}
#endif

public static string CacheDirectory
Expand Down
4 changes: 4 additions & 0 deletions UnityGLTF/Assets/UnityGLTF/Runtime/Scripts/GLTFSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ public enum BlendShapeExportPropertyFlags
[SerializeField]
[Tooltip("If off, vertex colors are not exported. Vertex Colors aren't supported in some viewers (e.g. Google's SceneViewer).")]
private bool exportVertexColors = true;
[Header("Cache")]
[Tooltip("When enabled textures will be cached to disc for faster export times (the cache size is reduced to stay below 200 MB when quit)")]
public bool UseCaching = true;

public bool ExportNames { get => exportNames; set => exportNames = value; }
public bool ExportFullPath { get => exportFullPath; set => exportFullPath = value; }
Expand All @@ -130,6 +133,7 @@ public enum BlendShapeExportPropertyFlags
public BlendShapeExportPropertyFlags BlendShapeExportProperties { get => blendShapeExportProperties; set => blendShapeExportProperties = value; }
public bool BakeSkinnedMeshes { get => bakeSkinnedMeshes; set => bakeSkinnedMeshes = value; }


#if UNITY_EDITOR
private const string SaveFolderPathPref = k_PreferencesPrefix + "SaveFolderPath";
public string SaveFolderPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ private ImageId ExportImageInternalBuffer(UniqueTexture uniqueTexture, string te
image.MimeType = canExportAsJpeg ? JPEGMimeType : PNGMimeType;

var cacheKey = uniqueTexture.GetHashCode().ToString();
if (ExportCache.TryGetBytes(texture, cacheKey, out var bytes))
if (settings.UseCaching && ExportCache.TryGetBytes(texture, cacheKey, out var bytes))
{
_bufferWriter.Write(bytes);
}
Expand All @@ -604,7 +604,9 @@ private ImageId ExportImageInternalBuffer(UniqueTexture uniqueTexture, string te

var imageData = canExportAsJpeg ? exportTexture.EncodeToJPG(settings.DefaultJpegQuality) : exportTexture.EncodeToPNG();
_bufferWriter.Write(imageData);
ExportCache.AddBytes(texture, cacheKey, imageData);

if(settings.UseCaching)
ExportCache.AddBytes(texture, cacheKey, imageData);

GL.sRGBWrite = previousSRGBState;

Expand Down

0 comments on commit a7a5dd4

Please sign in to comment.