Skip to content

Commit

Permalink
rm empty meta file, fix inline method with await warning when no KTX2…
Browse files Browse the repository at this point in the history
… loader is present
  • Loading branch information
hybridherbst committed Oct 18, 2021
1 parent 3f69f5a commit ca5469e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.

This file was deleted.

37 changes: 19 additions & 18 deletions UnityGLTF/Assets/UnityGLTF/Runtime/Scripts/GLTFSceneImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -755,21 +755,16 @@ protected async Task ConstructImage(GLTFImage image, int imageCacheIndex, bool m
}


protected virtual async Task ConstructUnityTexture(Stream stream, bool markGpuOnly, bool isLinear, GLTFImage image, int imageCacheIndex)
async Task CheckMimeTypeAndLoadImage(GLTFImage image, Texture2D texture, byte[] data, bool markGpuOnly)
{
Texture2D texture = new Texture2D(0, 0, TextureFormat.RGBA32, GenerateMipMapsForTextures, isLinear);
texture.name = string.IsNullOrEmpty(image.Name) ? Path.GetFileNameWithoutExtension(image.Uri) : image.Name;

async Task CheckMimeTypeAndLoadImage(byte[] data)
switch (image.MimeType)
{
switch (image.MimeType)
{
case "image/png":
case "image/jpeg":
// NOTE: the second parameter of LoadImage() marks non-readable, but we can't mark it until after we call Apply()
texture.LoadImage(data, markGpuOnly);
break;
case "image/ktx2":
case "image/png":
case "image/jpeg":
// NOTE: the second parameter of LoadImage() marks non-readable, but we can't mark it until after we call Apply()
texture.LoadImage(data, markGpuOnly);
break;
case "image/ktx2":
#if HAVE_KTX
// TODO doesn't work yet, blocks?
// var ktxTexture = new KtxUnity.KtxTexture();
Expand All @@ -781,18 +776,24 @@ async Task CheckMimeTypeAndLoadImage(byte[] data)
// texture.name = tmp.name;
// }
#else
Debug.LogWarning("The KTX2 Texture Format (KHR_texture_basisu) isn't supported right now. The texture " + texture.name + " won't load and will be black. Try using glTFast instead.");
Debug.LogWarning("The KTX2 Texture Format (KHR_texture_basisu) isn't supported right now. The texture " + texture.name + " won't load and will be black. Try using glTFast instead.");
await Task.CompletedTask;
#endif
break;
}
break;
}
}

protected virtual async Task ConstructUnityTexture(Stream stream, bool markGpuOnly, bool isLinear, GLTFImage image, int imageCacheIndex)
{
Texture2D texture = new Texture2D(0, 0, TextureFormat.RGBA32, GenerateMipMapsForTextures, isLinear);
texture.name = string.IsNullOrEmpty(image.Name) ? Path.GetFileNameWithoutExtension(image.Uri) : image.Name;

if (stream is MemoryStream)
{
using (MemoryStream memoryStream = stream as MemoryStream)
{
await YieldOnTimeoutAndThrowOnLowMemory();
await CheckMimeTypeAndLoadImage(memoryStream.ToArray());
await CheckMimeTypeAndLoadImage(image, texture, memoryStream.ToArray(), markGpuOnly);
}
}
else
Expand All @@ -807,7 +808,7 @@ async Task CheckMimeTypeAndLoadImage(byte[] data)
stream.Read(buffer, 0, (int)stream.Length);

await YieldOnTimeoutAndThrowOnLowMemory();
await CheckMimeTypeAndLoadImage(buffer);
await CheckMimeTypeAndLoadImage(image, texture, buffer, markGpuOnly);
}

Debug.Assert(_assetCache.ImageCache[imageCacheIndex] == null, "ImageCache should not be loaded multiple times");
Expand Down

0 comments on commit ca5469e

Please sign in to comment.