Merge pull request #2354 from saturday06/vrm0-export-gltf-normal-texture

VRM0のMToonエクスポート時にノーマルマップテクスチャをglTFのマテリアルにもエクスポートするようにした
This commit is contained in:
Masataka SUMI
2024-07-08 18:41:06 +09:00
committed by GitHub

View File

@@ -32,6 +32,7 @@ namespace VRM
ExportRenderingSettings(srcProps, dst);
ExportBaseColor(src, srcProps, textureExporter, dst);
ExportEmission(src, srcProps, textureExporter, dst);
ExportNormal(src, srcProps, textureExporter, dst);
return true;
}
@@ -116,6 +117,23 @@ namespace VRM
}
}
private static void ExportNormal(Material srcMaterial, MToonDefinition src, ITextureExporter textureExporter, glTFMaterial dst)
{
if (src.Lighting.Normal.NormalTexture != null)
{
var index = textureExporter.RegisterExportingAsNormal(src.Lighting.Normal.NormalTexture);
if (index != -1)
{
dst.normalTexture = new glTFMaterialNormalTextureInfo()
{
index = index,
scale = src.Lighting.Normal.NormalScaleValue,
};
ExportMainTextureTransform(srcMaterial, dst.normalTexture);
}
}
}
private static void ExportMainTextureTransform(Material src, glTFTextureInfo targetTextureInfo)
{
GltfMaterialExportUtils.ExportTextureTransform(src, targetTextureInfo, MToon.Utils.PropMainTex);