mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-07-30 22:46:44 -05:00
make enum private
This commit is contained in:
parent
1d6f58feb5
commit
7963c4fe5c
|
|
@ -1,9 +1,20 @@
|
|||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VRMShaders
|
||||
{
|
||||
/// <summary>
|
||||
/// Texture を用途別に変換の要不要を判断して gltf.textures の index に対応させる機能。
|
||||
///
|
||||
/// glTF 拡張で Texture の用途を増やす必要がある場合は、この interface を継承して実装すればよい。
|
||||
/// </summary>
|
||||
public interface ITextureExporter
|
||||
{
|
||||
/// <summary>
|
||||
/// Export する Texture2D のリスト。これが gltf.textures になる
|
||||
/// </summary>
|
||||
IReadOnlyList<(Texture2D, UniGLTF.ColorSpace)> Exported { get; }
|
||||
|
||||
int ExportSRGB(Texture src);
|
||||
int ExportLinear(Texture src);
|
||||
int ExportMetallicSmoothnessOcclusion(Texture metallicSmoothTexture, float smoothness, Texture occlusionTexture);
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
namespace VRMShaders
|
||||
{
|
||||
public enum TextureExportTypes
|
||||
{
|
||||
// 無変換
|
||||
None,
|
||||
// Unity Standard様式 から glTF PBR様式への変換
|
||||
OcclusionMetallicRoughness,
|
||||
// Assetを使うときはそのバイト列を無変換で、それ以外は DXT5nm 形式からのデコードを行う
|
||||
Normal,
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c2182c41d0d7469baec383d0069938e6
|
||||
timeCreated: 1621508069
|
||||
|
|
@ -13,7 +13,11 @@ namespace VRMShaders
|
|||
/// </summary>
|
||||
public class TextureExporter : IDisposable, ITextureExporter
|
||||
{
|
||||
private ITextureSerializer m_textureSerializer;
|
||||
private readonly ITextureSerializer m_textureSerializer;
|
||||
private readonly Dictionary<ExportKey, int> m_exportMap = new Dictionary<ExportKey, int>();
|
||||
private readonly List<(Texture2D, ColorSpace)> m_exported = new List<(Texture2D, ColorSpace)>();
|
||||
|
||||
public IReadOnlyList<(Texture2D, ColorSpace)> Exported => m_exported;
|
||||
|
||||
public TextureExporter(ITextureSerializer textureSerializer)
|
||||
{
|
||||
|
|
@ -25,12 +29,22 @@ namespace VRMShaders
|
|||
// TODO: export 用にコピー・変換したテクスチャーをここで解放したい
|
||||
}
|
||||
|
||||
struct ExportKey
|
||||
enum ExportTypes
|
||||
{
|
||||
// 無変換
|
||||
None,
|
||||
// Unity Standard様式 から glTF PBR様式への変換
|
||||
OcclusionMetallicRoughness,
|
||||
// Assetを使うときはそのバイト列を無変換で、それ以外は DXT5nm 形式からのデコードを行う
|
||||
Normal,
|
||||
}
|
||||
|
||||
readonly struct ExportKey
|
||||
{
|
||||
public readonly Texture Src;
|
||||
public readonly TextureExportTypes TextureType;
|
||||
public readonly ExportTypes TextureType;
|
||||
|
||||
public ExportKey(Texture src, TextureExportTypes type)
|
||||
public ExportKey(Texture src, ExportTypes type)
|
||||
{
|
||||
if (src == null)
|
||||
{
|
||||
|
|
@ -40,29 +54,6 @@ namespace VRMShaders
|
|||
TextureType = type;
|
||||
}
|
||||
}
|
||||
Dictionary<ExportKey, int> m_exportMap = new Dictionary<ExportKey, int>();
|
||||
|
||||
/// <summary>
|
||||
/// Export する Texture2D のリスト。これが gltf.textures になる
|
||||
/// </summary>
|
||||
/// <typeparam name="Texture2D"></typeparam>
|
||||
/// <returns></returns>
|
||||
public readonly List<(Texture2D, ColorSpace)> Exported = new List<(Texture2D, ColorSpace)>();
|
||||
|
||||
/// <summary>
|
||||
/// Texture の export index を得る
|
||||
/// </summary>
|
||||
/// <param name="src"></param>
|
||||
/// <param name="textureType"></param>
|
||||
/// <returns></returns>
|
||||
public int GetTextureIndex(Texture src, TextureExportTypes textureType)
|
||||
{
|
||||
if (src == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return m_exportMap[new ExportKey(src, textureType)];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// sRGBなテクスチャーを処理し、index を確定させる
|
||||
|
|
@ -77,13 +68,13 @@ namespace VRMShaders
|
|||
}
|
||||
|
||||
// cache
|
||||
if (m_exportMap.TryGetValue(new ExportKey(src, TextureExportTypes.None), out var index))
|
||||
if (m_exportMap.TryGetValue(new ExportKey(src, ExportTypes.None), out var index))
|
||||
{
|
||||
return index;
|
||||
}
|
||||
|
||||
// get Texture2D
|
||||
index = Exported.Count;
|
||||
index = m_exported.Count;
|
||||
var texture2D = src as Texture2D;
|
||||
if (m_textureSerializer.CanExportAsEditorAssetFile(texture2D))
|
||||
{
|
||||
|
|
@ -93,8 +84,8 @@ namespace VRMShaders
|
|||
{
|
||||
texture2D = TextureConverter.CopyTexture(src, TextureImportTypes.sRGB, null);
|
||||
}
|
||||
Exported.Add((texture2D, ColorSpace.sRGB));
|
||||
m_exportMap.Add(new ExportKey(src, TextureExportTypes.None), index);
|
||||
m_exported.Add((texture2D, ColorSpace.sRGB));
|
||||
m_exportMap.Add(new ExportKey(src, ExportTypes.None), index);
|
||||
|
||||
return index;
|
||||
}
|
||||
|
|
@ -111,7 +102,7 @@ namespace VRMShaders
|
|||
return -1;
|
||||
}
|
||||
|
||||
var exportKey = new ExportKey(src, TextureExportTypes.None);
|
||||
var exportKey = new ExportKey(src, ExportTypes.None);
|
||||
|
||||
// search cache
|
||||
if (m_exportMap.TryGetValue(exportKey, out var index))
|
||||
|
|
@ -119,7 +110,7 @@ namespace VRMShaders
|
|||
return index;
|
||||
}
|
||||
|
||||
index = Exported.Count;
|
||||
index = m_exported.Count;
|
||||
var texture2d = src as Texture2D;
|
||||
if (m_textureSerializer.CanExportAsEditorAssetFile(texture2d))
|
||||
{
|
||||
|
|
@ -129,7 +120,7 @@ namespace VRMShaders
|
|||
{
|
||||
texture2d = TextureConverter.CopyTexture(src, TextureImportTypes.Linear, null);
|
||||
}
|
||||
Exported.Add((texture2d, ColorSpace.Linear));
|
||||
m_exported.Add((texture2d, ColorSpace.Linear));
|
||||
m_exportMap.Add(exportKey, index);
|
||||
|
||||
return index;
|
||||
|
|
@ -150,11 +141,11 @@ namespace VRMShaders
|
|||
}
|
||||
|
||||
// cache
|
||||
if (metallicSmoothTexture != null && m_exportMap.TryGetValue(new ExportKey(metallicSmoothTexture, TextureExportTypes.OcclusionMetallicRoughness), out var index))
|
||||
if (metallicSmoothTexture != null && m_exportMap.TryGetValue(new ExportKey(metallicSmoothTexture, ExportTypes.OcclusionMetallicRoughness), out var index))
|
||||
{
|
||||
return index;
|
||||
}
|
||||
if (occlusionTexture != null && m_exportMap.TryGetValue(new ExportKey(occlusionTexture, TextureExportTypes.OcclusionMetallicRoughness), out index))
|
||||
if (occlusionTexture != null && m_exportMap.TryGetValue(new ExportKey(occlusionTexture, ExportTypes.OcclusionMetallicRoughness), out index))
|
||||
{
|
||||
return index;
|
||||
}
|
||||
|
|
@ -162,17 +153,17 @@ namespace VRMShaders
|
|||
//
|
||||
// Unity と glTF で互換性が無いので必ず変換が必用
|
||||
//
|
||||
index = Exported.Count;
|
||||
index = m_exported.Count;
|
||||
var texture2D = OcclusionMetallicRoughnessConverter.Export(metallicSmoothTexture, smoothness, occlusionTexture);
|
||||
|
||||
Exported.Add((texture2D, ColorSpace.Linear));
|
||||
m_exported.Add((texture2D, ColorSpace.Linear));
|
||||
if (metallicSmoothTexture != null)
|
||||
{
|
||||
m_exportMap.Add(new ExportKey(metallicSmoothTexture, TextureExportTypes.OcclusionMetallicRoughness), index);
|
||||
m_exportMap.Add(new ExportKey(metallicSmoothTexture, ExportTypes.OcclusionMetallicRoughness), index);
|
||||
}
|
||||
if (occlusionTexture != null && occlusionTexture != metallicSmoothTexture)
|
||||
{
|
||||
m_exportMap.Add(new ExportKey(occlusionTexture, TextureExportTypes.OcclusionMetallicRoughness), index);
|
||||
m_exportMap.Add(new ExportKey(occlusionTexture, ExportTypes.OcclusionMetallicRoughness), index);
|
||||
}
|
||||
|
||||
return index;
|
||||
|
|
@ -191,13 +182,13 @@ namespace VRMShaders
|
|||
}
|
||||
|
||||
// cache
|
||||
if (m_exportMap.TryGetValue(new ExportKey(src, TextureExportTypes.Normal), out var index))
|
||||
if (m_exportMap.TryGetValue(new ExportKey(src, ExportTypes.Normal), out var index))
|
||||
{
|
||||
return index;
|
||||
}
|
||||
|
||||
// get Texture2D
|
||||
index = Exported.Count;
|
||||
index = m_exported.Count;
|
||||
var texture2D = src as Texture2D;
|
||||
if (m_textureSerializer.CanExportAsEditorAssetFile(texture2D))
|
||||
{
|
||||
|
|
@ -209,8 +200,8 @@ namespace VRMShaders
|
|||
texture2D = NormalConverter.Export(src);
|
||||
}
|
||||
|
||||
Exported.Add((texture2D, ColorSpace.Linear));
|
||||
m_exportMap.Add(new ExportKey(src, TextureExportTypes.Normal), index);
|
||||
m_exported.Add((texture2D, ColorSpace.Linear));
|
||||
m_exportMap.Add(new ExportKey(src, ExportTypes.Normal), index);
|
||||
|
||||
return index;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user