From d3439abc528abe8563ac1b1a4ce950d3717aa77b Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Sat, 3 Aug 2024 01:00:53 +0900 Subject: [PATCH] Implements UrpFallbackMaterialExporter --- .../Materials/UrpFallbackMaterialExporter.cs | 36 +++++++++++++++++++ .../UrpFallbackMaterialExporter.cs.meta | 3 ++ 2 files changed, 39 insertions(+) create mode 100644 Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpFallbackMaterialExporter.cs create mode 100644 Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpFallbackMaterialExporter.cs.meta diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpFallbackMaterialExporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpFallbackMaterialExporter.cs new file mode 100644 index 000000000..c590d4e93 --- /dev/null +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpFallbackMaterialExporter.cs @@ -0,0 +1,36 @@ +using System; +using UnityEngine; + +namespace UniGLTF +{ + /// + /// フォールバック目的で最低限なにかをエクスポートする。 + /// + /// メインカラーとメインテクスチャをエクスポートする。 + /// + 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; + } + } +} \ No newline at end of file diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpFallbackMaterialExporter.cs.meta b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpFallbackMaterialExporter.cs.meta new file mode 100644 index 000000000..908fd8446 --- /dev/null +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpFallbackMaterialExporter.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c0269be076674f5988895ecd61b8d316 +timeCreated: 1722612454 \ No newline at end of file