mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-07 03:17:25 -05:00
rename & use interface
This commit is contained in:
@@ -15,12 +15,12 @@ namespace UniGLTF
|
||||
|
||||
public interface IMaterialExporter
|
||||
{
|
||||
glTFMaterial ExportMaterial(Material m, TextureExporter textureExporter);
|
||||
glTFMaterial ExportMaterial(Material m, ITextureExporter textureExporter);
|
||||
}
|
||||
|
||||
public class MaterialExporter : IMaterialExporter
|
||||
{
|
||||
public virtual glTFMaterial ExportMaterial(Material m, TextureExporter textureExporter)
|
||||
public virtual glTFMaterial ExportMaterial(Material m, ITextureExporter textureExporter)
|
||||
{
|
||||
var material = CreateMaterial(m);
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace UniGLTF
|
||||
return material;
|
||||
}
|
||||
|
||||
static void Export_Color(Material m, TextureExporter textureManager, glTFMaterial material)
|
||||
static void Export_Color(Material m, ITextureExporter textureManager, glTFMaterial material)
|
||||
{
|
||||
if (m.HasProperty("_Color"))
|
||||
{
|
||||
@@ -60,9 +60,9 @@ namespace UniGLTF
|
||||
/// Occlusion, Metallic, Roughness
|
||||
/// </summary>
|
||||
/// <param name="m"></param>
|
||||
/// <param name="textureManager"></param>
|
||||
/// <param name="textureExporter"></param>
|
||||
/// <param name="material"></param>
|
||||
static void Export_OcclusionMetallicRoughness(Material m, TextureExporter textureManager, glTFMaterial material)
|
||||
static void Export_OcclusionMetallicRoughness(Material m, ITextureExporter textureExporter, glTFMaterial material)
|
||||
{
|
||||
Texture metallicSmoothTexture = default;
|
||||
float smoothness = 1.0f;
|
||||
@@ -88,7 +88,7 @@ namespace UniGLTF
|
||||
}
|
||||
}
|
||||
|
||||
int index = textureManager.ExportMetallicSmoothnessOcclusion(metallicSmoothTexture, smoothness, occlusionTexture);
|
||||
int index = textureExporter.ExportMetallicSmoothnessOcclusion(metallicSmoothTexture, smoothness, occlusionTexture);
|
||||
|
||||
if (index != -1 && metallicSmoothTexture != null)
|
||||
{
|
||||
@@ -127,11 +127,11 @@ namespace UniGLTF
|
||||
}
|
||||
}
|
||||
|
||||
static void Export_Normal(Material m, TextureExporter textureManager, glTFMaterial material)
|
||||
static void Export_Normal(Material m, ITextureExporter textureExporter, glTFMaterial material)
|
||||
{
|
||||
if (m.HasProperty("_BumpMap"))
|
||||
{
|
||||
var index = textureManager.ExportNormal(m.GetTexture("_BumpMap"));
|
||||
var index = textureExporter.ExportNormal(m.GetTexture("_BumpMap"));
|
||||
if (index != -1)
|
||||
{
|
||||
material.normalTexture = new glTFMaterialNormalTextureInfo()
|
||||
@@ -149,7 +149,7 @@ namespace UniGLTF
|
||||
}
|
||||
}
|
||||
|
||||
static void Export_Emission(Material m, TextureExporter textureManager, glTFMaterial material)
|
||||
static void Export_Emission(Material m, ITextureExporter textureExporter, glTFMaterial material)
|
||||
{
|
||||
if (m.IsKeywordEnabled("_EMISSION") == false)
|
||||
return;
|
||||
@@ -166,7 +166,7 @@ namespace UniGLTF
|
||||
|
||||
if (m.HasProperty("_EmissionMap"))
|
||||
{
|
||||
var index = textureManager.ExportSRGB(m.GetTexture("_EmissionMap"));
|
||||
var index = textureExporter.ExportSRGB(m.GetTexture("_EmissionMap"));
|
||||
if (index != -1)
|
||||
{
|
||||
material.emissiveTexture = new glTFMaterialEmissiveTextureInfo()
|
||||
|
||||
@@ -43,7 +43,11 @@ namespace UniGLTF
|
||||
private set;
|
||||
}
|
||||
|
||||
public TextureExporter TextureManager;
|
||||
public TextureExporter TextureExporter
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
protected virtual IMaterialExporter CreateMaterialExporter()
|
||||
{
|
||||
@@ -238,10 +242,10 @@ namespace UniGLTF
|
||||
#region Materials and Textures
|
||||
Materials = uniqueUnityMeshes.SelectMany(x => x.Renderer.sharedMaterials).Where(x => x != null).Distinct().ToList();
|
||||
|
||||
TextureManager = new TextureExporter(textureSerializer);
|
||||
TextureExporter = new TextureExporter(textureSerializer);
|
||||
|
||||
var materialExporter = CreateMaterialExporter();
|
||||
glTF.materials = Materials.Select(x => materialExporter.ExportMaterial(x, TextureManager)).ToList();
|
||||
glTF.materials = Materials.Select(x => materialExporter.ExportMaterial(x, TextureExporter)).ToList();
|
||||
#endregion
|
||||
|
||||
#region Meshes
|
||||
@@ -360,9 +364,9 @@ namespace UniGLTF
|
||||
ExportExtensions(textureSerializer);
|
||||
|
||||
// Extension で Texture が増える場合があるので最後に呼ぶ
|
||||
for (int i = 0; i < TextureManager.Exported.Count; ++i)
|
||||
for (int i = 0; i < TextureExporter.Exported.Count; ++i)
|
||||
{
|
||||
var (unityTexture, colorSpace) = TextureManager.Exported[i];
|
||||
var (unityTexture, colorSpace) = TextureExporter.Exported[i];
|
||||
glTF.PushGltfTexture(bufferIndex, unityTexture, colorSpace, textureSerializer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace UniGLTF
|
||||
filterMode = FilterMode.Bilinear,
|
||||
};
|
||||
|
||||
var textureManager = new TextureExporter(new EditorTextureSerializer());
|
||||
var textureExporter = new TextureExporter(new EditorTextureSerializer());
|
||||
var srcMaterial = new Material(Shader.Find("Standard"));
|
||||
|
||||
var offset = new Vector2(0.3f, 0.2f);
|
||||
@@ -29,7 +29,7 @@ namespace UniGLTF
|
||||
srcMaterial.mainTextureScale = scale;
|
||||
|
||||
var materialExporter = new MaterialExporter();
|
||||
var gltfMaterial = materialExporter.ExportMaterial(srcMaterial, textureManager);
|
||||
var gltfMaterial = materialExporter.ExportMaterial(srcMaterial, textureExporter);
|
||||
gltfMaterial.pbrMetallicRoughness.baseColorTexture.extensions = gltfMaterial.pbrMetallicRoughness.baseColorTexture.extensions.Deserialize();
|
||||
|
||||
Assert.IsTrue(glTF_KHR_texture_transform.TryGet(gltfMaterial.pbrMetallicRoughness.baseColorTexture, out glTF_KHR_texture_transform t));
|
||||
@@ -242,8 +242,8 @@ namespace UniGLTF
|
||||
material.SetColor("_EmissionColor", new Color(0, 1, 2, 1));
|
||||
material.EnableKeyword("_EMISSION");
|
||||
var materialExporter = new MaterialExporter();
|
||||
var textureExportManager = new TextureExporter(new EditorTextureSerializer());
|
||||
var gltfMaterial = materialExporter.ExportMaterial(material, textureExportManager);
|
||||
var textureExporter = new TextureExporter(new EditorTextureSerializer());
|
||||
var gltfMaterial = materialExporter.ExportMaterial(material, textureExporter);
|
||||
|
||||
Assert.AreEqual(gltfMaterial.emissiveFactor, new float[] { 0, 0.5f, 1 });
|
||||
}
|
||||
|
||||
@@ -18,15 +18,15 @@ namespace UniGLTF
|
||||
wrapMode = TextureWrapMode.Clamp,
|
||||
filterMode = FilterMode.Trilinear,
|
||||
};
|
||||
var textureManager = new TextureExporter(new EditorTextureSerializer());
|
||||
var textureExporter = new TextureExporter(new EditorTextureSerializer());
|
||||
|
||||
var material = new Material(Shader.Find("Standard"));
|
||||
material.mainTexture = tex0;
|
||||
|
||||
var materialExporter = new MaterialExporter();
|
||||
materialExporter.ExportMaterial(material, textureManager);
|
||||
materialExporter.ExportMaterial(material, textureExporter);
|
||||
|
||||
var (convTex0, colorSpace) = textureManager.Exported[0];
|
||||
var (convTex0, colorSpace) = textureExporter.Exported[0];
|
||||
var sampler = TextureSamplerUtil.Export(convTex0);
|
||||
|
||||
Assert.AreEqual(glWrap.CLAMP_TO_EDGE, sampler.wrapS);
|
||||
|
||||
@@ -11,8 +11,8 @@ namespace VRM.Samples
|
||||
{
|
||||
var material = Resources.Load<Material>(resourceName);
|
||||
var exporter = new VRMMaterialExporter();
|
||||
var textureManager = new TextureExporter(new EditorTextureSerializer());
|
||||
var exported = exporter.ExportMaterial(material, textureManager);
|
||||
var textureExporter = new TextureExporter(new EditorTextureSerializer());
|
||||
var exported = exporter.ExportMaterial(material, textureExporter);
|
||||
|
||||
// parse glTFExtensionExport to glTFExtensionImport
|
||||
exported.extensions = exported.extensions.Deserialize();
|
||||
|
||||
@@ -136,7 +136,7 @@ namespace VRM
|
||||
VRM.meta.title = meta.Title;
|
||||
if (meta.Thumbnail != null)
|
||||
{
|
||||
VRM.meta.texture = TextureManager.ExportSRGB(meta.Thumbnail);
|
||||
VRM.meta.texture = TextureExporter.ExportSRGB(meta.Thumbnail);
|
||||
}
|
||||
|
||||
// ussage permission
|
||||
@@ -199,7 +199,7 @@ namespace VRM
|
||||
// materials
|
||||
foreach (var m in Materials)
|
||||
{
|
||||
VRM.materialProperties.Add(VRMMaterialExporter.CreateFromMaterial(m, TextureManager));
|
||||
VRM.materialProperties.Add(VRMMaterialExporter.CreateFromMaterial(m, TextureExporter));
|
||||
}
|
||||
|
||||
// Serialize VRM
|
||||
|
||||
@@ -126,7 +126,7 @@ namespace VRM
|
||||
// "Queue",
|
||||
};
|
||||
|
||||
public static glTF_VRM_Material CreateFromMaterial(Material m, TextureExporter textureExporter)
|
||||
public static glTF_VRM_Material CreateFromMaterial(Material m, ITextureExporter textureExporter)
|
||||
{
|
||||
var material = new glTF_VRM_Material
|
||||
{
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace VRM
|
||||
filterMode = FilterMode.Bilinear,
|
||||
};
|
||||
|
||||
var textureManager = new TextureExporter(new EditorTextureSerializer());
|
||||
var textureExporter = new TextureExporter(new EditorTextureSerializer());
|
||||
var srcMaterial = new Material(Shader.Find("VRM/MToon"));
|
||||
|
||||
var offset = new Vector2(0.3f, 0.2f);
|
||||
@@ -29,7 +29,7 @@ namespace VRM
|
||||
srcMaterial.mainTextureScale = scale;
|
||||
|
||||
var materialExporter = new VRMMaterialExporter();
|
||||
var vrmMaterial = VRMMaterialExporter.CreateFromMaterial(srcMaterial, textureManager);
|
||||
var vrmMaterial = VRMMaterialExporter.CreateFromMaterial(srcMaterial, textureExporter);
|
||||
Assert.AreEqual(vrmMaterial.vectorProperties["_MainTex"], new float[] { 0.3f, 0.2f, 0.5f, 0.6f });
|
||||
|
||||
var materialImporter = new VRMMaterialImporter(new glTF_VRM_extensions
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace UniVRM10
|
||||
{
|
||||
public static class Vrm10MToonMaterialExporter
|
||||
{
|
||||
public static bool TryExportMaterialAsMToon(Material src, TextureExporter textureExporter, out glTFMaterial dst)
|
||||
public static bool TryExportMaterialAsMToon(Material src, ITextureExporter textureExporter, out glTFMaterial dst)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace UniVRM10
|
||||
{
|
||||
public class Vrm10MaterialExporter : MaterialExporter
|
||||
{
|
||||
public override glTFMaterial ExportMaterial(Material m, TextureExporter textureExporter)
|
||||
public override glTFMaterial ExportMaterial(Material m, ITextureExporter textureExporter)
|
||||
{
|
||||
if (Vrm10MToonMaterialExporter.TryExportMaterialAsMToon(m, textureExporter, out var dst))
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace VRMShaders
|
||||
/// glTF にエクスポートする Texture2D を蓄えて index を確定させる。
|
||||
/// Exporter の最後でまとめて Texture2D から bytes 列を得て出力する。
|
||||
/// </summary>
|
||||
public class TextureExporter : IDisposable, ITextureExporter
|
||||
public sealed class TextureExporter : IDisposable, ITextureExporter
|
||||
{
|
||||
private readonly ITextureSerializer m_textureSerializer;
|
||||
private readonly Dictionary<ExportKey, int> m_exportMap = new Dictionary<ExportKey, int>();
|
||||
|
||||
Reference in New Issue
Block a user