mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-10-02 07:42:25 -05:00
Consider colorspace
This commit is contained in:
@@ -19,7 +19,7 @@ namespace VRMShaders
|
||||
/// * TextureImporter の maxSize
|
||||
///
|
||||
/// </summary>
|
||||
public bool CanExportAsEditorAssetFile(Texture texture)
|
||||
public bool CanExportAsEditorAssetFile(Texture texture, ColorSpace exportColorSpace)
|
||||
{
|
||||
if (texture is Texture2D texture2D && !string.IsNullOrEmpty(UnityEditor.AssetDatabase.GetAssetPath(texture2D)))
|
||||
{
|
||||
@@ -42,14 +42,14 @@ namespace VRMShaders
|
||||
return false;
|
||||
}
|
||||
|
||||
public (byte[] bytes, string mime) ExportBytesWithMime(Texture2D texture, ColorSpace textureColorSpace)
|
||||
public (byte[] bytes, string mime) ExportBytesWithMime(Texture2D texture, ColorSpace exportColorSpace)
|
||||
{
|
||||
if (CanExportAsEditorAssetFile(texture) && TryGetBytesWithMime(texture, out byte[] bytes, out string mime))
|
||||
if (CanExportAsEditorAssetFile(texture, exportColorSpace) && TryGetBytesWithMime(texture, out byte[] bytes, out string mime))
|
||||
{
|
||||
return (bytes, mime);
|
||||
}
|
||||
|
||||
return m_runtimeSerializer.ExportBytesWithMime(texture, textureColorSpace);
|
||||
return m_runtimeSerializer.ExportBytesWithMime(texture, exportColorSpace);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -10,16 +10,17 @@ namespace UniGLTF
|
||||
/// <summary>
|
||||
/// Texture をファイルのバイト列そのまま出力してよいかどうか判断する。
|
||||
///
|
||||
/// exportColorSpace はその Texture2D がアサインされる glTF プロパティの仕様が定める色空間を指定する。
|
||||
/// Runtime 出力では常に false が望ましい。
|
||||
/// </summary>
|
||||
bool CanExportAsEditorAssetFile(Texture texture);
|
||||
bool CanExportAsEditorAssetFile(Texture texture, ColorSpace exportColorSpace);
|
||||
|
||||
/// <summary>
|
||||
/// Texture2D から実際のバイト列を取得する。
|
||||
///
|
||||
/// textureColorSpace はその Texture2D がアサインされる glTF プロパティの仕様が定める色空間を指定する。
|
||||
/// exportColorSpace はその Texture2D がアサインされる glTF プロパティの仕様が定める色空間を指定する。
|
||||
/// 具体的には Texture2D をコピーする際に、コピー先の Texture2D の色空間を決定するために使用する。
|
||||
/// </summary>
|
||||
(byte[] bytes, string mime) ExportBytesWithMime(Texture2D texture, ColorSpace textureColorSpace);
|
||||
(byte[] bytes, string mime) ExportBytesWithMime(Texture2D texture, ColorSpace exportColorSpace);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,12 +6,12 @@ namespace UniGLTF
|
||||
{
|
||||
public sealed class RuntimeTextureSerializer : ITextureSerializer
|
||||
{
|
||||
public bool CanExportAsEditorAssetFile(Texture texture)
|
||||
public bool CanExportAsEditorAssetFile(Texture texture, ColorSpace exportColorSpace)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public (byte[] bytes, string mime) ExportBytesWithMime(Texture2D texture, ColorSpace textureColorSpace)
|
||||
public (byte[] bytes, string mime) ExportBytesWithMime(Texture2D texture, ColorSpace exportColorSpace)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -24,7 +24,7 @@ namespace UniGLTF
|
||||
{
|
||||
// Failed, because texture is compressed.
|
||||
// ex. ".DDS" file, or Compression is enabled in Texture Import Settings.
|
||||
return CopyTextureAndGetBytesWithMime(texture, textureColorSpace);
|
||||
return CopyTextureAndGetBytesWithMime(texture, exportColorSpace);
|
||||
}
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
@@ -35,7 +35,7 @@ namespace UniGLTF
|
||||
Debug.LogWarning(ex);
|
||||
|
||||
// 単純に EncodeToPNG できないため、コピーしてから EncodeToPNG する。
|
||||
return CopyTextureAndGetBytesWithMime(texture, textureColorSpace);
|
||||
return CopyTextureAndGetBytesWithMime(texture, exportColorSpace);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace VRMShaders
|
||||
// get Texture2D
|
||||
index = m_exported.Count;
|
||||
var texture2D = src as Texture2D;
|
||||
if (m_textureSerializer.CanExportAsEditorAssetFile(texture2D))
|
||||
if (m_textureSerializer.CanExportAsEditorAssetFile(texture2D, ColorSpace.sRGB))
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
@@ -114,7 +114,7 @@ namespace VRMShaders
|
||||
|
||||
index = m_exported.Count;
|
||||
var texture2d = src as Texture2D;
|
||||
if (m_textureSerializer.CanExportAsEditorAssetFile(texture2d))
|
||||
if (m_textureSerializer.CanExportAsEditorAssetFile(texture2d, ColorSpace.Linear))
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
@@ -193,7 +193,7 @@ namespace VRMShaders
|
||||
// get Texture2D
|
||||
index = m_exported.Count;
|
||||
var texture2D = src as Texture2D;
|
||||
if (m_textureSerializer.CanExportAsEditorAssetFile(texture2D))
|
||||
if (m_textureSerializer.CanExportAsEditorAssetFile(texture2D, ColorSpace.Linear))
|
||||
{
|
||||
// EditorAsset を使うので変換不要
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user