Merge pull request #2610 from matsutaka-pxv/texture-marknonreadable
Some checks failed
Expired Issues Closure / cycle-weekly-close (push) Has been cancelled

Add: UnitySupportedImageTypeDeserializer に MarkNonReadable プロパティを追加
This commit is contained in:
ousttrue 2025-03-14 16:40:27 +09:00 committed by GitHub
commit 38c4313d95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -9,6 +9,18 @@ namespace UniGLTF
/// </summary>
public sealed class UnitySupportedImageTypeDeserializer : ITextureDeserializer
{
/// <summary>
/// `true` を指定すると、テクスチャを Non-Readable なものとしてデシリアライズする。
/// </summary>
/// <remarks>
/// `UnityEngine.ImageConversion.LoadImage` の第二引数 `markNonReadable` に相当。
/// デフォルト値は `false`。
/// テクスチャ編集を行わないアプリケーションプログラム等では、
/// この値を `true` にすることでメモリ使用量の削減を期待できる。
/// このフラグの効用については `UnityEngine.Texture2D.Apply` に記述がある。
/// </remarks>
public bool MarkNonReadable { get; set; } = false;
public async Task<Texture2D> LoadTextureAsync(DeserializingTextureInfo textureInfo, IAwaitCaller awaitCaller)
{
if (textureInfo.ImageData == null) return null;
@ -16,7 +28,7 @@ namespace UniGLTF
try
{
var texture = new Texture2D(2, 2, TextureFormat.ARGB32, textureInfo.UseMipmap, textureInfo.ColorSpace == ColorSpace.Linear);
texture.LoadImage(textureInfo.ImageData);
texture.LoadImage(textureInfo.ImageData, MarkNonReadable);
await awaitCaller.NextFrame();
texture.wrapModeU = textureInfo.WrapModeU;