ImporterContext に引数追加。runtime のデフォルト値を MarkNonReadable = true に変更

This commit is contained in:
ousttrue 2025-04-04 02:00:43 +09:00
parent 5949353126
commit 59f89f6e8f
4 changed files with 46 additions and 6 deletions

View File

@ -48,7 +48,7 @@ namespace UniGLTF
MaterialDescriptorGenerator = materialGenerator ?? MaterialDescriptorGeneratorUtility.GetValidGltfMaterialDescriptorGenerator();
ExternalObjectMap = externalObjectMap ?? new Dictionary<SubAssetKey, UnityEngine.Object>();
textureDeserializer = textureDeserializer ?? new UnityTextureDeserializer();
textureDeserializer = textureDeserializer ?? new UnityTextureDeserializer(_settings.MarkNonReadable);
TextureFactory = new TextureFactory(textureDeserializer, ExternalObjectMap
.Where(x => x.Value is Texture)

View File

@ -1,19 +1,47 @@
namespace UniGLTF
using UnityEngine;
namespace UniGLTF
{
/// <summary>
/// ImporterContext層の設定はここに。
/// さすれば、VRMとVRM10を変えずに設定を追加できる。
/// </summary>
public class ImporterContextSettings
{
public bool LoadAnimation { get; }
public Axes InvertAxis { get; }
public bool TextureIsReadalbe { get; }
public bool MarkNonReadable => !TextureIsReadalbe;
/// <summary>
/// ImporterContextの設定を指定する。
/// </summary>
/// <param name="loadAnimation">アニメーションをインポートする場合はtrueを指定(初期値はtrue)</param>
/// <param name="invertAxis">GLTF から Unity に変換するときに反転させる軸を指定(初期値はAxes.Z)</param>
public ImporterContextSettings(bool loadAnimation = true, Axes invertAxis = Axes.Z)
/// <param name="textureIsReadable">textureのbitmapにアクセスするか(初期値はEditorの場合はtrue。それ以外はfalse)</param>
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;
}
}
}
}
}

View File

@ -14,12 +14,19 @@ namespace UniGLTF
/// </summary>
/// <remarks>
/// `UnityEngine.ImageConversion.LoadImage` の第二引数 `markNonReadable` に相当。
/// デフォルト値は `false`。
/// テクスチャ編集を行わないアプリケーションプログラム等では、
/// この値を `true` にすることでメモリ使用量の削減を期待できる。
/// このフラグの効用については `UnityEngine.Texture2D.Apply` に記述がある。
///
/// v0.128.4
/// default は ImporterContextSettings.MarkNonReadable に従う
/// </remarks>
public bool MarkNonReadable { get; set; } = false;
public bool MarkNonReadable { get; }
public UnitySupportedImageTypeDeserializer(bool markNonReadable)
{
MarkNonReadable = markNonReadable;
}
public async Task<Texture2D> LoadTextureAsync(DeserializingTextureInfo textureInfo, IAwaitCaller awaitCaller)
{

View File

@ -8,9 +8,14 @@ namespace UniGLTF
/// </summary>
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<Texture2D> LoadTextureAsync(DeserializingTextureInfo textureInfo, IAwaitCaller awaitCaller)
{
Texture2D texture = null;