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;