Implements Universal Render Pipeline/Unlit Material Exporter

This commit is contained in:
Masataka SUMI
2024-08-03 01:12:54 +09:00
parent 39c01b2966
commit 5f7a38989c
3 changed files with 51 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
using System;
using UnityEngine;
namespace UniGLTF
{
public class UrpUnlitMaterialExporter
{
public Shader Shader { get; set; }
/// <summary>
/// "Universal Render Pipeline/Unlit" シェーダのマテリアルをエクスポートする。
///
/// プロパティに互換性がある他のシェーダを指定することもできる。
/// </summary>
public UrpUnlitMaterialExporter(Shader shader = null)
{
Shader = shader != null ? shader : Shader.Find("Universal Render Pipeline/Unlit");
}
public bool TryExportMaterial(Material src, ITextureExporter textureExporter, out glTFMaterial dst)
{
try
{
if (src == null) throw new ArgumentNullException(nameof(src));
if (src.shader != Shader) throw new ArgumentException(nameof(src));
if (textureExporter == null) throw new ArgumentNullException(nameof(textureExporter));
dst = glTF_KHR_materials_unlit.CreateDefault();
dst.name = src.name;
var context = new UrpLitContext(src);
UrpLitMaterialExporter.ExportSurfaceSettings(context, dst, textureExporter);
UrpLitMaterialExporter.ExportBaseColor(context, dst, textureExporter);
return true;
}
catch (Exception e)
{
Debug.LogException(e);
dst = default;
return false;
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a90bb1e911744bbab916950324c70e52
timeCreated: 1722614768

View File

@@ -5,12 +5,14 @@ namespace UniGLTF
public class UrpGltfMaterialExporter : IMaterialExporter
{
public UrpLitMaterialExporter UrpLitExporter { get; set; } = new();
public UrpUnlitMaterialExporter UrpUnlitExporter { get; set; } = new();
public UrpUniUnlitMaterialExporter UrpUniUnlitExporter { get; set; } = new();
public UrpFallbackMaterialExporter FallbackExporter { get; set; } = new();
public glTFMaterial ExportMaterial(Material m, ITextureExporter textureExporter, GltfExportSettings settings)
{
if (UrpLitExporter.TryExportMaterial(m, textureExporter, out var dst)) return dst;
if (UrpUnlitExporter.TryExportMaterial(m, textureExporter, out dst)) return dst;
if (UrpUniUnlitExporter.TryExportMaterial(m, textureExporter, out dst)) return dst;
Debug.Log($"Material `{m.name}` fallbacks.");