mv MaterialImporter MaterialDescriptorGenerator

This commit is contained in:
Masataka SUMI 2021-05-27 16:00:16 +09:00
parent 8cba3ba71a
commit c456c9ddf7
17 changed files with 30 additions and 30 deletions

View File

@ -33,7 +33,7 @@ namespace UniGLTF
#endregion
public ITextureDescriptorGenerator TextureDescriptorGenerator { get; protected set; }
public IMaterialImporter MaterialImporter { get; protected set; }
public IMaterialDescriptorGenerator MaterialDescriptorGenerator { get; protected set; }
public TextureFactory TextureFactory { get; }
public MaterialFactory MaterialFactory { get; }
@ -41,7 +41,7 @@ namespace UniGLTF
{
Parser = parser;
TextureDescriptorGenerator = new GltfTextureDescriptorGenerator(Parser);
MaterialImporter = new GltfMaterialImporter();
MaterialDescriptorGenerator = new GltfMaterialDescriptorGenerator();
externalObjectMap = externalObjectMap ?? new Dictionary<SubAssetKey, UnityEngine.Object>();
TextureFactory = new TextureFactory(externalObjectMap
@ -195,14 +195,14 @@ namespace UniGLTF
if (Parser.GLTF.materials == null || Parser.GLTF.materials.Count == 0)
{
// no material. work around.
var param = MaterialImporter.GetMaterialParam(Parser, 0);
var param = MaterialDescriptorGenerator.Get(Parser, 0);
var material = await MaterialFactory.LoadAsync(param, TextureFactory.GetTextureAsync);
}
else
{
for (int i = 0; i < Parser.GLTF.materials.Count; ++i)
{
var param = MaterialImporter.GetMaterialParam(Parser, i);
var param = MaterialDescriptorGenerator.Get(Parser, i);
var material = await MaterialFactory.LoadAsync(param, TextureFactory.GetTextureAsync);
}
}

View File

@ -8,9 +8,9 @@ namespace UniGLTF
/// <summary>
/// GLTF の MaterialImporter
/// </summary>
public sealed class GltfMaterialImporter : IMaterialImporter
public sealed class GltfMaterialDescriptorGenerator : IMaterialDescriptorGenerator
{
public MaterialDescriptor GetMaterialParam(GltfParser parser, int i)
public MaterialDescriptor Get(GltfParser parser, int i)
{
if (!GltfUnlitMaterialImporter.TryCreateParam(parser, i, out var param))
{

View File

@ -56,7 +56,7 @@ namespace UniGLTF
}
var src = parser.GLTF.materials[i];
matDesc = new MaterialDescriptor(GltfMaterialImporter.GetMaterialName(i, src), ShaderName);
matDesc = new MaterialDescriptor(GltfMaterialDescriptorGenerator.GetMaterialName(i, src), ShaderName);
var standardTexDesc = default(TextureDescriptor);
if (src.pbrMetallicRoughness != null || src.occlusionTexture != null)

View File

@ -23,7 +23,7 @@ namespace UniGLTF
return false;
}
matDesc = new MaterialDescriptor(GltfMaterialImporter.GetMaterialName(i, src), ShaderName);
matDesc = new MaterialDescriptor(GltfMaterialDescriptorGenerator.GetMaterialName(i, src), ShaderName);
// texture
if (src.pbrMetallicRoughness.baseColorTexture != null)

View File

@ -6,8 +6,8 @@ namespace UniGLTF
/// 指定の index の glTFMaterial から Import できる Material の生成情報を生成する。
/// glTFMaterial と Unity Material は 1:1 対応する。
/// </summary>
public interface IMaterialImporter
public interface IMaterialDescriptorGenerator
{
MaterialDescriptor GetMaterialParam(GltfParser parser, int i);
MaterialDescriptor Get(GltfParser parser, int i);
}
}

View File

@ -208,10 +208,10 @@ namespace UniGLTF
var parser = new GltfParser();
parser.ParsePath(path);
var materialParam = new GltfMaterialImporter().GetMaterialParam(parser, 0);
Assert.AreEqual("Standard", materialParam.ShaderName);
Assert.AreEqual(5, materialParam.TextureSlots.Count);
var (key, value) = materialParam.EnumerateSubAssetKeyValue().First();
var matDesc = new GltfMaterialDescriptorGenerator().Get(parser, 0);
Assert.AreEqual("Standard", matDesc.ShaderName);
Assert.AreEqual(5, matDesc.TextureSlots.Count);
var (key, value) = matDesc.EnumerateSubAssetKeyValue().First();
Assert.AreEqual(new SubAssetKey(typeof(Texture2D), "texture_0"), key);
}
}

View File

@ -103,7 +103,7 @@ namespace VRM
// extract converted textures
//
var subAssets = m_context.TextureFactory.ConvertedTextures;
var vrmTextures = new VRMMaterialImporter(m_context.VRM);
var vrmTextures = new VRMMaterialDescriptorGenerator(m_context.VRM);
var dirName = $"{m_prefabPath.FileNameWithoutExtension}.Textures";
TextureExtractor.ExtractTextures(m_context.Parser, m_prefabPath.Parent.Child(dirName), m_context.TextureDescriptorGenerator, subAssets, (_x, _y) => { }, onTextureReloaded);
}

View File

@ -28,7 +28,7 @@ namespace VRM
{
VRM = vrm;
TextureDescriptorGenerator = new VrmTextureDescriptorGenerator(Parser, VRM);
MaterialImporter = new VRMMaterialImporter(VRM);
MaterialDescriptorGenerator = new VRMMaterialDescriptorGenerator(VRM);
}
else
{

View File

@ -6,15 +6,15 @@ using VRMShaders;
namespace VRM
{
public sealed class VRMMaterialImporter : IMaterialImporter
public sealed class VRMMaterialDescriptorGenerator : IMaterialDescriptorGenerator
{
readonly glTF_VRM_extensions m_vrm;
public VRMMaterialImporter(glTF_VRM_extensions vrm)
public VRMMaterialDescriptorGenerator(glTF_VRM_extensions vrm)
{
m_vrm = vrm;
}
public MaterialDescriptor GetMaterialParam(GltfParser parser, int i)
public MaterialDescriptor Get(GltfParser parser, int i)
{
// mtoon
if (!VRMMToonMaterialImporter.TryCreateParam(parser, m_vrm, i, out MaterialDescriptor matDesc))
@ -29,7 +29,7 @@ namespace VRM
#if VRM_DEVELOP
Debug.LogWarning($"material: {i} out of range. fallback");
#endif
return new MaterialDescriptor(GltfMaterialImporter.GetMaterialName(i, null), GltfPbrMaterialImporter.ShaderName);
return new MaterialDescriptor(GltfMaterialDescriptorGenerator.GetMaterialName(i, null), GltfPbrMaterialImporter.ShaderName);
}
}
}

View File

@ -32,7 +32,7 @@ namespace VRM
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
var materialImporter = new VRMMaterialDescriptorGenerator(new glTF_VRM_extensions
{
materialProperties = new System.Collections.Generic.List<glTF_VRM_Material> { vrmMaterial }
});
@ -70,7 +70,7 @@ namespace VRM
var parser = new GltfParser();
parser.ParsePath(AliciaPath);
var vrmImporter = new VRMImporterContext(parser, null);
var materialParam = new VRMMaterialImporter(vrmImporter.VRM).GetMaterialParam(parser, 0);
var materialParam = new VRMMaterialDescriptorGenerator(vrmImporter.VRM).Get(parser, 0);
Assert.AreEqual("VRM/MToon", materialParam.ShaderName);
Assert.AreEqual("Alicia_body", materialParam.TextureSlots["_MainTex"].UnityObjectName);

View File

@ -4,9 +4,9 @@ using VRMShaders;
namespace UniVRM10
{
public sealed class Vrm10MaterialImporter : IMaterialImporter
public sealed class Vrm10MaterialDescriptorGenerator : IMaterialDescriptorGenerator
{
public MaterialDescriptor GetMaterialParam(GltfParser parser, int i)
public MaterialDescriptor Get(GltfParser parser, int i)
{
// mtoon
if (!Vrm10MToonMaterialImporter.TryCreateParam(parser, i, out MaterialDescriptor matDesc))
@ -21,7 +21,7 @@ namespace UniVRM10
#if VRM_DEVELOP
Debug.LogWarning($"material: {i} out of range. fallback");
#endif
return new MaterialDescriptor(GltfMaterialImporter.GetMaterialName(i, null), GltfPbrMaterialImporter.ShaderName);
return new MaterialDescriptor(GltfMaterialDescriptorGenerator.GetMaterialName(i, null), GltfPbrMaterialImporter.ShaderName);
}
}
}

View File

@ -25,7 +25,7 @@ namespace UniVRM10
: base(parser, externalObjectMap)
{
TextureDescriptorGenerator = new Vrm10TextureDescriptorGenerator(parser);
MaterialImporter = new Vrm10MaterialImporter();
MaterialDescriptorGenerator = new Vrm10MaterialDescriptorGenerator();
m_externalMap = externalObjectMap;
if (m_externalMap == null)

View File

@ -25,11 +25,11 @@ namespace UniVRM10
var parser = new GltfParser();
parser.Parse(AliciaPath, migratedBytes);
var materialParam = new Vrm10MaterialImporter().GetMaterialParam(parser, 0);
Assert.AreEqual("VRM/MToon", materialParam.ShaderName);
Assert.AreEqual("Alicia_body", materialParam.TextureSlots["_MainTex"].UnityObjectName);
var matDesc = new Vrm10MaterialDescriptorGenerator().Get(parser, 0);
Assert.AreEqual("VRM/MToon", matDesc.ShaderName);
Assert.AreEqual("Alicia_body", matDesc.TextureSlots["_MainTex"].UnityObjectName);
var (key, value) = materialParam.EnumerateSubAssetKeyValue().First();
var (key, value) = matDesc.EnumerateSubAssetKeyValue().First();
Assert.AreEqual(new SubAssetKey(typeof(Texture2D), "Alicia_body"), key);
}
}