Implements UrpFallbackMaterialExporter

This commit is contained in:
Masataka SUMI 2024-08-03 01:00:53 +09:00
parent 182fdbe8b0
commit d3439abc52
No known key found for this signature in database
GPG Key ID: 84BC1D606F3D8551
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,36 @@
using System;
using UnityEngine;
namespace UniGLTF
{
/// <summary>
/// フォールバック目的で最低限なにかをエクスポートする。
///
/// メインカラーとメインテクスチャをエクスポートする。
/// </summary>
public class UrpFallbackMaterialExporter
{
public glTFMaterial ExportMaterial(Material src, ITextureExporter textureExporter)
{
var dst = new glTFMaterial
{
name = src.name,
pbrMetallicRoughness = new glTFPbrMetallicRoughness(),
};
dst.pbrMetallicRoughness.baseColorFactor = src.color.ToFloat4(ColorSpace.sRGB, ColorSpace.Linear);
var index = textureExporter.RegisterExportingAsSRgb(src.mainTexture, false);
if (index >= 0)
{
dst.pbrMetallicRoughness.baseColorTexture = new glTFMaterialBaseColorTextureInfo
{
index = index,
texCoord = 0,
};
GltfMaterialExportUtils.ExportTextureTransform(src.mainTextureOffset, src.mainTextureScale, dst.pbrMetallicRoughness.baseColorTexture);
}
return dst;
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c0269be076674f5988895ecd61b8d316
timeCreated: 1722612454