mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-01 07:23:15 -05:00
Merge pull request #2625 from ousttrue/fiix/isTextureReadable
ImporterContextSettings に引数追加。runtime のデフォルト値を MarkNonReadable = true に変更
This commit is contained in:
commit
e36c43207a
|
|
@ -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.ImportedTexturesAccessibility);
|
||||
|
||||
TextureFactory = new TextureFactory(textureDeserializer, ExternalObjectMap
|
||||
.Where(x => x.Value is Texture)
|
||||
|
|
|
|||
|
|
@ -1,19 +1,31 @@
|
|||
namespace UniGLTF
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
/// <summary>
|
||||
/// ImporterContext層の設定はここに。
|
||||
/// さすれば、VRMとVRM10を変えずに設定を追加できる。
|
||||
/// </summary>
|
||||
public class ImporterContextSettings
|
||||
{
|
||||
public bool LoadAnimation { get; }
|
||||
public Axes InvertAxis { get; }
|
||||
public ImportedTexturesAccessibility ImportedTexturesAccessibility { get; }
|
||||
|
||||
/// <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,
|
||||
ImportedTexturesAccessibility importedTexturesAccessibility = ImportedTexturesAccessibility.Auto)
|
||||
{
|
||||
LoadAnimation = loadAnimation;
|
||||
InvertAxis = invertAxis;
|
||||
ImportedTexturesAccessibility = importedTexturesAccessibility;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
/// <summary>
|
||||
/// Accessibility of imported texture bitmap
|
||||
/// </summary>
|
||||
public enum ImportedTexturesAccessibility
|
||||
{
|
||||
/// <summary>
|
||||
/// Platform dependent.
|
||||
/// see: ToMarkNonReadable()
|
||||
/// </summary>
|
||||
Auto,
|
||||
|
||||
/// <summary>
|
||||
/// Bitmaps are accessible.
|
||||
/// Specify explicitly when exporting an imported model again.
|
||||
/// <summary>
|
||||
Readable,
|
||||
|
||||
/// <summary>
|
||||
/// It can save memory usage. Recommended.
|
||||
/// </summary>
|
||||
NonReadable,
|
||||
}
|
||||
|
||||
public static class TextureReadableParamExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// convert to Texture2D.LoadImage param
|
||||
/// </summary>
|
||||
public static bool ToMarkNonReadable(this ImportedTexturesAccessibility self)
|
||||
{
|
||||
switch (self)
|
||||
{
|
||||
case ImportedTexturesAccessibility.Auto:
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
// change behaviour from v0.128.4
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
case ImportedTexturesAccessibility.Readable:
|
||||
return false;
|
||||
|
||||
case ImportedTexturesAccessibility.NonReadable:
|
||||
return true;
|
||||
|
||||
default:
|
||||
throw new ArgumentException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3fd49b42a267f4a449d22012f6997398
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -14,12 +14,18 @@ namespace UniGLTF
|
|||
/// </summary>
|
||||
/// <remarks>
|
||||
/// `UnityEngine.ImageConversion.LoadImage` の第二引数 `markNonReadable` に相当。
|
||||
/// デフォルト値は `false`。
|
||||
/// テクスチャ編集を行わないアプリケーションプログラム等では、
|
||||
/// この値を `true` にすることでメモリ使用量の削減を期待できる。
|
||||
/// このフラグの効用については `UnityEngine.Texture2D.Apply` に記述がある。
|
||||
///
|
||||
/// v0.128.4 ImportedTexturesAccessibility を参照
|
||||
/// </remarks>
|
||||
public bool MarkNonReadable { get; set; } = false;
|
||||
public ImportedTexturesAccessibility ImportedTexturesAccessibility { get; } = ImportedTexturesAccessibility.Auto;
|
||||
|
||||
public UnitySupportedImageTypeDeserializer(ImportedTexturesAccessibility importedTexturesAccessibility)
|
||||
{
|
||||
ImportedTexturesAccessibility = importedTexturesAccessibility;
|
||||
}
|
||||
|
||||
public async Task<Texture2D> LoadTextureAsync(DeserializingTextureInfo textureInfo, IAwaitCaller awaitCaller)
|
||||
{
|
||||
|
|
@ -28,7 +34,7 @@ namespace UniGLTF
|
|||
try
|
||||
{
|
||||
var texture = new Texture2D(2, 2, TextureFormat.ARGB32, textureInfo.UseMipmap, textureInfo.ColorSpace == ColorSpace.Linear);
|
||||
texture.LoadImage(textureInfo.ImageData, MarkNonReadable);
|
||||
texture.LoadImage(textureInfo.ImageData, ImportedTexturesAccessibility.ToMarkNonReadable());
|
||||
await awaitCaller.NextFrame();
|
||||
|
||||
texture.wrapModeU = textureInfo.WrapModeU;
|
||||
|
|
|
|||
|
|
@ -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(ImportedTexturesAccessibility importedTexturesAccessibility)
|
||||
{
|
||||
_unitySupportedDeserializer = new(importedTexturesAccessibility);
|
||||
}
|
||||
|
||||
public async Task<Texture2D> LoadTextureAsync(DeserializingTextureInfo textureInfo, IAwaitCaller awaitCaller)
|
||||
{
|
||||
Texture2D texture = null;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user