mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-13 06:20:01 -05:00
Implements Universal Render Pipeline/Unlit Material Exporter
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a90bb1e911744bbab916950324c70e52
|
||||
timeCreated: 1722614768
|
||||
@@ -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.");
|
||||
|
||||
Reference in New Issue
Block a user