From 59f89f6e8f2e31c540e396c88bd579b8dfcf9e53 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 4 Apr 2025 02:00:43 +0900 Subject: [PATCH] =?UTF-8?q?ImporterContext=20=E3=81=AB=E5=BC=95=E6=95=B0?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E3=80=82runtime=20=E3=81=AE=E3=83=87?= =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=AB=E3=83=88=E5=80=A4=E3=82=92=20MarkNo?= =?UTF-8?q?nReadable=20=3D=20true=20=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runtime/UniGLTF/IO/ImporterContext.cs | 2 +- .../UniGLTF/IO/ImporterContextSettings.cs | 32 +++++++++++++++++-- .../UnitySupportedImageTypeDeserializer.cs | 11 +++++-- .../Import/UnityTextureDeserializer.cs | 7 +++- 4 files changed, 46 insertions(+), 6 deletions(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs index ce31fbc6c..60f0ad957 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs @@ -48,7 +48,7 @@ namespace UniGLTF MaterialDescriptorGenerator = materialGenerator ?? MaterialDescriptorGeneratorUtility.GetValidGltfMaterialDescriptorGenerator(); ExternalObjectMap = externalObjectMap ?? new Dictionary(); - textureDeserializer = textureDeserializer ?? new UnityTextureDeserializer(); + textureDeserializer = textureDeserializer ?? new UnityTextureDeserializer(_settings.MarkNonReadable); TextureFactory = new TextureFactory(textureDeserializer, ExternalObjectMap .Where(x => x.Value is Texture) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContextSettings.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContextSettings.cs index 262a71719..f4eda4b50 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContextSettings.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContextSettings.cs @@ -1,19 +1,47 @@ -namespace UniGLTF +using UnityEngine; + +namespace UniGLTF { + /// + /// ImporterContext層の設定はここに。 + /// さすれば、VRMとVRM10を変えずに設定を追加できる。 + /// public class ImporterContextSettings { public bool LoadAnimation { get; } public Axes InvertAxis { get; } + public bool TextureIsReadalbe { get; } + public bool MarkNonReadable => !TextureIsReadalbe; /// /// ImporterContextの設定を指定する。 /// /// アニメーションをインポートする場合はtrueを指定(初期値はtrue) /// GLTF から Unity に変換するときに反転させる軸を指定(初期値はAxes.Z) - public ImporterContextSettings(bool loadAnimation = true, Axes invertAxis = Axes.Z) + /// textureのbitmapにアクセスするか(初期値はEditorの場合はtrue。それ以外はfalse) + public ImporterContextSettings( + bool loadAnimation = true, + Axes invertAxis = Axes.Z, + bool? textureIsReadable = default) { LoadAnimation = loadAnimation; InvertAxis = invertAxis; + if (textureIsReadable.HasValue) + { + TextureIsReadalbe = textureIsReadable.Value; + } + else + { + if (Application.isEditor) + { + TextureIsReadalbe = true; + } + else + { + // v0.128.4 からの挙動変更 + TextureIsReadalbe = false; + } + } } } } \ No newline at end of file diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/Import/UnitySupportedImageTypeDeserializer.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/Import/UnitySupportedImageTypeDeserializer.cs index 05a71c1df..1ae7b6f89 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/Import/UnitySupportedImageTypeDeserializer.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/Import/UnitySupportedImageTypeDeserializer.cs @@ -14,12 +14,19 @@ namespace UniGLTF /// /// /// `UnityEngine.ImageConversion.LoadImage` の第二引数 `markNonReadable` に相当。 - /// デフォルト値は `false`。 /// テクスチャ編集を行わないアプリケーションプログラム等では、 /// この値を `true` にすることでメモリ使用量の削減を期待できる。 /// このフラグの効用については `UnityEngine.Texture2D.Apply` に記述がある。 + /// + /// v0.128.4 + /// default は ImporterContextSettings.MarkNonReadable に従う /// - public bool MarkNonReadable { get; set; } = false; + public bool MarkNonReadable { get; } + + public UnitySupportedImageTypeDeserializer(bool markNonReadable) + { + MarkNonReadable = markNonReadable; + } public async Task LoadTextureAsync(DeserializingTextureInfo textureInfo, IAwaitCaller awaitCaller) { diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/Import/UnityTextureDeserializer.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/Import/UnityTextureDeserializer.cs index 491f89757..7ce56bbad 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/Import/UnityTextureDeserializer.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/Import/UnityTextureDeserializer.cs @@ -8,9 +8,14 @@ namespace UniGLTF /// public sealed class UnityTextureDeserializer : ITextureDeserializer { - private readonly UnitySupportedImageTypeDeserializer _unitySupportedDeserializer = new(); + private readonly UnitySupportedImageTypeDeserializer _unitySupportedDeserializer; private readonly KtxTextureDeserializer _ktxTextureDeserializer = new(); + public UnityTextureDeserializer(bool markNonReadable) + { + _unitySupportedDeserializer = new(markNonReadable); + } + public async Task LoadTextureAsync(DeserializingTextureInfo textureInfo, IAwaitCaller awaitCaller) { Texture2D texture = null;