mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-04-25 15:47:26 -05:00
Convert glTF Material Import classes from static to instance class.
This commit is contained in:
parent
ddf262e63e
commit
fc30e74a12
|
|
@ -5,14 +5,18 @@ using UnityEngine;
|
|||
namespace UniGLTF
|
||||
{
|
||||
/// <summary>
|
||||
/// GLTF の MaterialImporter
|
||||
/// A class that generates MaterialDescriptor by considering the extensions included in the glTF data to be imported.
|
||||
/// </summary>
|
||||
public sealed class BuiltInGltfMaterialDescriptorGenerator : IMaterialDescriptorGenerator
|
||||
{
|
||||
public BuiltInGltfPbrMaterialImporter PbrMaterialImporter { get; } = new();
|
||||
public BuiltInGltfDefaultMaterialImporter DefaultMaterialImporter { get; } = new();
|
||||
public BuiltInGltfUnlitMaterialImporter UnlitMaterialImporter { get; } = new();
|
||||
|
||||
public MaterialDescriptor Get(GltfData data, int i)
|
||||
{
|
||||
if (BuiltInGltfUnlitMaterialImporter.TryCreateParam(data, i, out var param)) return param;
|
||||
if (BuiltInGltfPbrMaterialImporter.TryCreateParam(data, i, out param)) return param;
|
||||
if (UnlitMaterialImporter.TryCreateParam(data, i, out var param)) return param;
|
||||
if (PbrMaterialImporter.TryCreateParam(data, i, out param)) return param;
|
||||
|
||||
// fallback
|
||||
if (Symbols.VRM_DEVELOP)
|
||||
|
|
@ -22,6 +26,6 @@ namespace UniGLTF
|
|||
return GetGltfDefault(GltfMaterialImportUtils.ImportMaterialName(i, null));
|
||||
}
|
||||
|
||||
public MaterialDescriptor GetGltfDefault(string materialName = null) => BuiltInGltfDefaultMaterialImporter.CreateParam(materialName);
|
||||
public MaterialDescriptor GetGltfDefault(string materialName = null) => DefaultMaterialImporter.CreateParam(materialName);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,16 +5,28 @@ using UnityEngine;
|
|||
namespace UniGLTF
|
||||
{
|
||||
/// <summary>
|
||||
/// Generate the descriptor of the glTF default material.
|
||||
/// A class that generates MaterialDescriptor for "Standard" shader based on glTF default Material specification.
|
||||
///
|
||||
/// https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#default-material
|
||||
/// </summary>
|
||||
public static class BuiltInGltfDefaultMaterialImporter
|
||||
public class BuiltInGltfDefaultMaterialImporter
|
||||
{
|
||||
public static MaterialDescriptor CreateParam(string materialName = null)
|
||||
/// <summary>
|
||||
/// Can be replaced with custom shaders that are compatible with "Standard" properties and keywords.
|
||||
/// </summary>
|
||||
public Shader Shader { get; set; }
|
||||
|
||||
public BuiltInGltfDefaultMaterialImporter(Shader shader = null)
|
||||
{
|
||||
Shader = shader != null ? shader : Shader.Find("Standard");
|
||||
}
|
||||
|
||||
public MaterialDescriptor CreateParam(string materialName = null)
|
||||
{
|
||||
// FIXME
|
||||
return new MaterialDescriptor(
|
||||
string.IsNullOrEmpty(materialName) ? "__default__" : materialName,
|
||||
BuiltInGltfPbrMaterialImporter.Shader,
|
||||
Shader,
|
||||
default,
|
||||
new Dictionary<string, TextureDescriptor>(),
|
||||
new Dictionary<string, float>(),
|
||||
|
|
|
|||
|
|
@ -5,44 +5,16 @@ using UnityEngine;
|
|||
namespace UniGLTF
|
||||
{
|
||||
/// <summary>
|
||||
/// Gltf から MaterialImportParam に変換する
|
||||
///
|
||||
/// StandardShader variables
|
||||
///
|
||||
/// _Color
|
||||
/// _MainTex
|
||||
/// _Cutoff
|
||||
/// _Glossiness
|
||||
/// _Metallic
|
||||
/// _MetallicGlossMap
|
||||
/// _BumpScale
|
||||
/// _BumpMap
|
||||
/// _Parallax
|
||||
/// _ParallaxMap
|
||||
/// _OcclusionStrength
|
||||
/// _OcclusionMap
|
||||
/// _EmissionColor
|
||||
/// _EmissionMap
|
||||
/// _DetailMask
|
||||
/// _DetailAlbedoMap
|
||||
/// _DetailNormalMapScale
|
||||
/// _DetailNormalMap
|
||||
/// _UVSec
|
||||
/// _EmissionScaleUI
|
||||
/// _EmissionColorUI
|
||||
/// _Mode
|
||||
/// _SrcBlend
|
||||
/// _DstBlend
|
||||
/// _ZWrite
|
||||
/// A class that generates MaterialDescriptor for "Standard" shader based on glTF Material specification.
|
||||
///
|
||||
/// https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#materials
|
||||
/// </summary>
|
||||
public static class BuiltInGltfPbrMaterialImporter
|
||||
public class BuiltInGltfPbrMaterialImporter
|
||||
{
|
||||
private static readonly int SrcBlend = Shader.PropertyToID("_SrcBlend");
|
||||
private static readonly int DstBlend = Shader.PropertyToID("_DstBlend");
|
||||
private static readonly int ZWrite = Shader.PropertyToID("_ZWrite");
|
||||
private static readonly int Cutoff = Shader.PropertyToID("_Cutoff");
|
||||
public static Shader Shader => Shader.Find("Standard");
|
||||
|
||||
private enum BlendMode
|
||||
{
|
||||
|
|
@ -52,7 +24,17 @@ namespace UniGLTF
|
|||
Transparent
|
||||
}
|
||||
|
||||
public static bool TryCreateParam(GltfData data, int i, out MaterialDescriptor matDesc)
|
||||
/// <summary>
|
||||
/// Can be replaced with custom shaders that are compatible with "Standard" properties and keywords.
|
||||
/// </summary>
|
||||
public Shader Shader { get; set; }
|
||||
|
||||
public BuiltInGltfPbrMaterialImporter(Shader shader = null)
|
||||
{
|
||||
Shader = shader != null ? shader : Shader.Find("Standard");
|
||||
}
|
||||
|
||||
public bool TryCreateParam(GltfData data, int i, out MaterialDescriptor matDesc)
|
||||
{
|
||||
if (i < 0 || i >= data.GLTF.materials.Count)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,13 +5,26 @@ using UnityEngine;
|
|||
|
||||
namespace UniGLTF
|
||||
{
|
||||
public static class BuiltInGltfUnlitMaterialImporter
|
||||
/// <summary>
|
||||
/// A class that generates MaterialDescriptor for "UnGLTF/UniUnlit" shader based on glTF Extension "KHR_materials_unlit".
|
||||
///
|
||||
/// https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_unlit
|
||||
/// </summary>
|
||||
public class BuiltInGltfUnlitMaterialImporter
|
||||
{
|
||||
private static readonly int Cutoff = Shader.PropertyToID("_Cutoff");
|
||||
|
||||
public static Shader Shader => Shader.Find(UniUnlitUtil.ShaderName);
|
||||
/// <summary>
|
||||
/// Can be replaced with custom shaders that are compatible with "UniGLTF/UniUnlit" properties and keywords.
|
||||
/// </summary>
|
||||
public Shader Shader { get; set; }
|
||||
|
||||
public static bool TryCreateParam(GltfData data, int i, out MaterialDescriptor matDesc)
|
||||
public BuiltInGltfUnlitMaterialImporter(Shader shader = null)
|
||||
{
|
||||
Shader = shader != null ? shader : Shader.Find(UniUnlitUtil.ShaderName);
|
||||
}
|
||||
|
||||
public bool TryCreateParam(GltfData data, int i, out MaterialDescriptor matDesc)
|
||||
{
|
||||
if (i < 0 || i >= data.GLTF.materials.Count)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,12 +6,15 @@ using UnityEngine.Rendering;
|
|||
namespace UniGLTF
|
||||
{
|
||||
/// <summary>
|
||||
/// Generate the descriptor of the glTF default material.
|
||||
/// A class that generates MaterialDescriptor for "Universal Render Pipeline/Lit" shader based on glTF default Material specification.
|
||||
///
|
||||
/// https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#default-material
|
||||
/// </summary>
|
||||
public class UrpGltfDefaultMaterialImporter
|
||||
{
|
||||
/// <summary>
|
||||
/// Can be replaced with custom shaders that are compatible with "Universal Render Pipeline/Lit" properties and keywords.
|
||||
/// </summary>
|
||||
public Shader Shader { get; set; }
|
||||
|
||||
public UrpGltfDefaultMaterialImporter(Shader shader = null)
|
||||
|
|
|
|||
|
|
@ -7,14 +7,14 @@ using UnityEngine.Rendering;
|
|||
namespace UniGLTF
|
||||
{
|
||||
/// <summary>
|
||||
/// glTF PBR to URP Lit.
|
||||
///
|
||||
/// see: https://github.com/Unity-Technologies/Graphics/blob/v7.5.3/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineMaterialUpgrader.cs#L354-L379
|
||||
/// A class that generates MaterialDescriptor for "Universal Render Pipeline/Lit" shader based on glTF Material specification.
|
||||
///
|
||||
/// https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#materials
|
||||
/// </summary>
|
||||
public class UrpGltfPbrMaterialImporter
|
||||
{
|
||||
/// <summary>
|
||||
/// Universal Render Pipeline/Lit とプロパティやキーワードに互換があるカスタムシェーダに置換可能。
|
||||
/// Can be replaced with custom shaders that are compatible with "Universal Render Pipeline/Lit" properties and keywords.
|
||||
/// </summary>
|
||||
public Shader Shader { get; set; }
|
||||
|
||||
|
|
|
|||
|
|
@ -3,16 +3,17 @@ using UnityEngine;
|
|||
namespace UniGLTF
|
||||
{
|
||||
/// <summary>
|
||||
/// GLTF の MaterialImporter
|
||||
/// A class that generates MaterialDescriptor by considering the extensions included in the glTF data to be imported.
|
||||
/// </summary>
|
||||
public sealed class UrpGltfMaterialDescriptorGenerator : IMaterialDescriptorGenerator
|
||||
{
|
||||
public UrpGltfPbrMaterialImporter PbrMaterialImporter { get; } = new();
|
||||
public UrpGltfDefaultMaterialImporter DefaultMaterialImporter { get; } = new();
|
||||
public BuiltInGltfUnlitMaterialImporter UnlitMaterialImporter { get; } = new();
|
||||
|
||||
public MaterialDescriptor Get(GltfData data, int i)
|
||||
{
|
||||
if (BuiltInGltfUnlitMaterialImporter.TryCreateParam(data, i, out var param)) return param;
|
||||
if (UnlitMaterialImporter.TryCreateParam(data, i, out var param)) return param;
|
||||
if (PbrMaterialImporter.TryCreateParam(data, i, out param)) return param;
|
||||
|
||||
// NOTE: Fallback to default material
|
||||
|
|
|
|||
|
|
@ -9,6 +9,10 @@ namespace VRM
|
|||
{
|
||||
private readonly glTF_VRM_extensions _vrm;
|
||||
|
||||
public BuiltInGltfPbrMaterialImporter PbrMaterialImporter { get; } = new();
|
||||
public BuiltInGltfDefaultMaterialImporter DefaultMaterialImporter { get; } = new();
|
||||
public BuiltInGltfUnlitMaterialImporter UnlitMaterialImporter { get; } = new();
|
||||
|
||||
public BuiltInVrmMaterialDescriptorGenerator(glTF_VRM_extensions vrm)
|
||||
{
|
||||
_vrm = vrm;
|
||||
|
|
@ -29,13 +33,13 @@ namespace VRM
|
|||
}
|
||||
|
||||
// unlit
|
||||
if (BuiltInGltfUnlitMaterialImporter.TryCreateParam(data, i, out matDesc))
|
||||
if (UnlitMaterialImporter.TryCreateParam(data, i, out matDesc))
|
||||
{
|
||||
return matDesc;
|
||||
}
|
||||
|
||||
// pbr
|
||||
if (BuiltInGltfPbrMaterialImporter.TryCreateParam(data, i, out matDesc))
|
||||
if (PbrMaterialImporter.TryCreateParam(data, i, out matDesc))
|
||||
{
|
||||
return matDesc;
|
||||
}
|
||||
|
|
@ -48,6 +52,6 @@ namespace VRM
|
|||
return GetGltfDefault(GltfMaterialImportUtils.ImportMaterialName(i, null));
|
||||
}
|
||||
|
||||
public MaterialDescriptor GetGltfDefault(string materialName = null) => BuiltInGltfDefaultMaterialImporter.CreateParam(materialName);
|
||||
public MaterialDescriptor GetGltfDefault(string materialName = null) => DefaultMaterialImporter.CreateParam(materialName);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ namespace VRM
|
|||
|
||||
public UrpGltfPbrMaterialImporter PbrMaterialImporter { get; } = new();
|
||||
public UrpGltfDefaultMaterialImporter DefaultMaterialImporter { get; } = new();
|
||||
public BuiltInGltfUnlitMaterialImporter UnlitMaterialImporter { get; } = new();
|
||||
|
||||
public UrpVrmMaterialDescriptorGenerator(glTF_VRM_extensions vrm)
|
||||
{
|
||||
|
|
@ -21,7 +22,7 @@ namespace VRM
|
|||
{
|
||||
// mtoon URP "MToon" shader is not ready. import fallback to unlit
|
||||
// unlit "UniUnlit" work in URP
|
||||
if (BuiltInGltfUnlitMaterialImporter.TryCreateParam(data, i, out var matDesc)) return matDesc;
|
||||
if (UnlitMaterialImporter.TryCreateParam(data, i, out var matDesc)) return matDesc;
|
||||
// pbr "Standard" to "Universal Render Pipeline/Lit"
|
||||
if (PbrMaterialImporter.TryCreateParam(data, i, out matDesc)) return matDesc;
|
||||
|
||||
|
|
|
|||
|
|
@ -7,14 +7,18 @@ namespace UniVRM10
|
|||
{
|
||||
public sealed class BuiltInVrm10MaterialDescriptorGenerator : IMaterialDescriptorGenerator
|
||||
{
|
||||
public BuiltInGltfPbrMaterialImporter PbrMaterialImporter { get; } = new();
|
||||
public BuiltInGltfDefaultMaterialImporter DefaultMaterialImporter { get; } = new();
|
||||
public BuiltInGltfUnlitMaterialImporter UnlitMaterialImporter { get; } = new();
|
||||
|
||||
public MaterialDescriptor Get(GltfData data, int i)
|
||||
{
|
||||
// mtoon
|
||||
if (BuiltInVrm10MToonMaterialImporter.TryCreateParam(data, i, out MaterialDescriptor matDesc)) return matDesc;
|
||||
// unlit
|
||||
if (BuiltInGltfUnlitMaterialImporter.TryCreateParam(data, i, out matDesc)) return matDesc;
|
||||
if (UnlitMaterialImporter.TryCreateParam(data, i, out matDesc)) return matDesc;
|
||||
// pbr
|
||||
if (BuiltInGltfPbrMaterialImporter.TryCreateParam(data, i, out matDesc)) return matDesc;
|
||||
if (PbrMaterialImporter.TryCreateParam(data, i, out matDesc)) return matDesc;
|
||||
|
||||
// fallback
|
||||
if (Symbols.VRM_DEVELOP)
|
||||
|
|
@ -24,6 +28,6 @@ namespace UniVRM10
|
|||
return GetGltfDefault(GltfMaterialImportUtils.ImportMaterialName(i, null));
|
||||
}
|
||||
|
||||
public MaterialDescriptor GetGltfDefault(string materialName = null) => BuiltInGltfDefaultMaterialImporter.CreateParam(materialName);
|
||||
public MaterialDescriptor GetGltfDefault(string materialName = null) => DefaultMaterialImporter.CreateParam(materialName);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,13 +9,14 @@ namespace UniVRM10
|
|||
{
|
||||
public UrpGltfPbrMaterialImporter PbrMaterialImporter { get; } = new();
|
||||
public UrpGltfDefaultMaterialImporter DefaultMaterialImporter { get; } = new();
|
||||
public BuiltInGltfUnlitMaterialImporter UnlitMaterialImporter { get; } = new();
|
||||
|
||||
public MaterialDescriptor Get(GltfData data, int i)
|
||||
{
|
||||
// mtoon
|
||||
if (UrpVrm10MToonMaterialImporter.TryCreateParam(data, i, out var matDesc)) return matDesc;
|
||||
// unlit
|
||||
if (BuiltInGltfUnlitMaterialImporter.TryCreateParam(data, i, out matDesc)) return matDesc;
|
||||
if (UnlitMaterialImporter.TryCreateParam(data, i, out matDesc)) return matDesc;
|
||||
// pbr
|
||||
if (PbrMaterialImporter.TryCreateParam(data, i, out matDesc)) return matDesc;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,9 +4,11 @@ namespace UniVRM10.VRM10Viewer
|
|||
{
|
||||
class UnlitMaterialImporter : IMaterialImporter
|
||||
{
|
||||
public BuiltInGltfUnlitMaterialImporter GltfUnlitMaterialImporter { get; } = new();
|
||||
|
||||
bool IMaterialImporter.TryCreateParam(GltfData data, int i, out MaterialDescriptor matDesc)
|
||||
{
|
||||
return BuiltInGltfUnlitMaterialImporter.TryCreateParam(data, i, out matDesc);
|
||||
return GltfUnlitMaterialImporter.TryCreateParam(data, i, out matDesc);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user