mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-07-19 00:31:52 -05:00
Implements fallbacked behaviour.
This commit is contained in:
parent
04c14a2b86
commit
b6744a653a
|
|
@ -40,6 +40,7 @@ namespace UniGLTF
|
|||
break;
|
||||
}
|
||||
|
||||
Debug.Log($"Material `{m.name}` fallbacks.");
|
||||
return BuiltInFallbackMaterialExporter.ExportMaterial(m, textureExporter);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,18 @@
|
|||
using UnityEngine;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using VRMShaders;
|
||||
using ColorSpace = VRMShaders.ColorSpace;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
/// <summary>
|
||||
/// 非対応のシェーダでも空のマテリアルを出力する.
|
||||
/// 非対応のシェーダでも、baseColor だけ読み取ったマテリアルにする.
|
||||
/// </summary>
|
||||
public static class BuiltInFallbackMaterialExporter
|
||||
{
|
||||
private const string ColorPropertyName = "_Color";
|
||||
private const string ColorTexturePropertyName = "_MainTex";
|
||||
|
||||
public static glTFMaterial ExportMaterial(Material src, ITextureExporter textureExporter)
|
||||
{
|
||||
var dst = new glTFMaterial
|
||||
|
|
@ -16,6 +21,20 @@ namespace UniGLTF
|
|||
pbrMetallicRoughness = new glTFPbrMetallicRoughness(),
|
||||
};
|
||||
|
||||
if (src.HasProperty(ColorPropertyName))
|
||||
{
|
||||
dst.pbrMetallicRoughness.baseColorFactor = src.GetColor(ColorPropertyName).ToFloat4(ColorSpace.sRGB, ColorSpace.Linear);
|
||||
}
|
||||
|
||||
if (src.HasProperty(ColorTexturePropertyName) && src.GetTexture(ColorTexturePropertyName) != null)
|
||||
{
|
||||
dst.pbrMetallicRoughness.baseColorTexture = new glTFMaterialBaseColorTextureInfo()
|
||||
{
|
||||
index = textureExporter.RegisterExportingAsSRgb(src.GetTexture(ColorTexturePropertyName), false),
|
||||
};
|
||||
GltfMaterialExportUtils.ExportTextureTransform(src, dst.pbrMetallicRoughness.baseColorTexture, ColorTexturePropertyName);
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user