static (UniGLTF.glTFMaterial, bool) ToProtobufMaterial(VrmLib.Material vrmlibMaterial, List <VrmLib.Texture> textures) { if (vrmlibMaterial is VrmLib.MToonMaterial mtoon) { // MToon var protobufMaterial = UniVRM10.MToonAdapter.MToonToGltf(mtoon, textures); return(protobufMaterial, true); } else if (vrmlibMaterial is VrmLib.UnlitMaterial unlit) { // Unlit var protobufMaterial = UniVRM10.MaterialAdapter.UnlitToGltf(unlit, textures); return(protobufMaterial, true); } else if (vrmlibMaterial is VrmLib.PBRMaterial pbr) { // PBR var protobufMaterial = UniVRM10.MaterialAdapter.PBRToGltf(pbr, textures); return(protobufMaterial, false); } else { throw new NotImplementedException(); } }
public static UnityEngine.Material CreateMaterialAsset(VrmLib.Material src, bool hasVertexColor, Dictionary <VrmLib.Texture, Texture2D> textures) { if (src is VrmLib.MToonMaterial mtoonSrc) { // MTOON var material = new Material(Shader.Find(MToon.Utils.ShaderName)); MToon.Utils.SetMToonParametersToMaterial(material, mtoonSrc.Definition.ToUnity(textures)); return(material); } if (src is VrmLib.UnlitMaterial unlitSrc) { return(CreateUnlitMaterial(unlitSrc, hasVertexColor, textures)); } if (src is VrmLib.PBRMaterial pbrSrc) { return(CreateStandardMaterial(pbrSrc, textures)); } throw new NotImplementedException($"unknown material: {src}"); }
VrmLib.Material Export10(Material m, Func <Texture, VrmLib.Texture.ColorSpaceTypes, VrmLib.Texture.TextureTypes, VrmLib.TextureInfo> map) { switch (m.shader.name) { case "VRM/MToon": { var def = MToon.Utils.GetMToonParametersFromMaterial(m); return(new VrmLib.MToonMaterial(m.name) { Definition = def.ToVrmLib(map), }); } case "Unlit/Color": return(new VrmLib.UnlitMaterial(m.name) { BaseColorFactor = m.color.FromUnitySrgbToLinear(), }); case "Unlit/Texture": return(new VrmLib.Material(m.name) { BaseColorTexture = map(m.mainTexture as Texture2D, VrmLib.Texture.ColorSpaceTypes.Srgb, VrmLib.Texture.TextureTypes.Default), }); case "Unlit/Transparent": return(new VrmLib.Material(m.name) { BaseColorTexture = map(m.mainTexture as Texture2D, VrmLib.Texture.ColorSpaceTypes.Srgb, VrmLib.Texture.TextureTypes.Default), AlphaMode = VrmLib.AlphaModeType.BLEND, }); case "Unlit/Transparent Cutout": return(new VrmLib.Material(m.name) { BaseColorTexture = map(m.mainTexture as Texture2D, VrmLib.Texture.ColorSpaceTypes.Srgb, VrmLib.Texture.TextureTypes.Default), AlphaMode = VrmLib.AlphaModeType.MASK, AlphaCutoff = m.GetFloat("_Cutoff"), }); case "UniGLTF/UniUnlit": { var material = new VrmLib.Material(m.name) { BaseColorFactor = m.color.FromUnitySrgbToLinear(), BaseColorTexture = map(m.mainTexture as Texture2D, VrmLib.Texture.ColorSpaceTypes.Srgb, VrmLib.Texture.TextureTypes.Default), AlphaMode = GetAlphaMode(m), DoubleSided = UniUnlit.Utils.GetCullMode(m) == UniUnlit.UniUnlitCullMode.Off, }; if (material.AlphaMode == VrmLib.AlphaModeType.MASK) { material.AlphaCutoff = m.GetFloat("_Cutoff"); } // TODO: VertexColorMode return(material); } default: return(ExportStandard(m, map)); } }