// SPDX-FileCopyrightText: 2024 Unity Technologies and the glTFast authors // SPDX-License-Identifier: Apache-2.0 #if UNITY_SHADER_GRAPH using System; using UnityEngine; namespace GLTFast.Export { using Logging; using Schema; /// [Obsolete("Use MaterialExport.GetDefaultMaterialExport instead.")] // TODO: Make private in next major release public class MetaMaterialExport : IMaterialExport where TLitExport : IMaterialExport, new() where TGltfShaderGraphExport : IMaterialExport, new() { /// public bool ConvertMaterial( UnityEngine.Material uMaterial, out Material material, IGltfWritable gltf, ICodeLogger logger ) { return MetaMaterialExportShaderGraphs .Instance .ConvertMaterial(uMaterial, out material, gltf, logger); } } /// /// Picks a fitting material exporter, based on the used shader. /// /// Fallback material exporter for Unity Standard/Lit shaders. /// Material exporter for glTFast shader graphs. class MetaMaterialExportShaderGraphs : IMaterialExport where TLitExport : IMaterialExport, new() where TGltfShaderGraphExport : IMaterialExport, new() { static TLitExport s_LitMaterialExport; static TGltfShaderGraphExport s_GltfShaderGraphMaterialExport; MetaMaterialExportShaderGraphs() { } public static MetaMaterialExportShaderGraphs Instance { get; } = new MetaMaterialExportShaderGraphs(); /// public bool ConvertMaterial( UnityEngine.Material uMaterial, out Material material, IGltfWritable gltf, ICodeLogger logger ) { IMaterialExport materialExport; var name = uMaterial.shader.name; #if UNITY_SHADER_GRAPH if (name.StartsWith("Shader Graphs/glTF-")) { if (!MetaMaterialExportBuiltIn.TryFindMatchingGltfUnlitMaterialExport(name, out materialExport)) { s_GltfShaderGraphMaterialExport ??= new TGltfShaderGraphExport(); materialExport = s_GltfShaderGraphMaterialExport; } } else #endif if (!MetaMaterialExportBuiltIn.TryFindMatchingGltfMaterialExport(name, out materialExport)) { s_LitMaterialExport ??= new TLitExport(); materialExport = s_LitMaterialExport; } return materialExport.ConvertMaterial(uMaterial, out material, gltf, logger); } } } #endif // UNITY_SHADER_GRAPH