// SPDX-FileCopyrightText: 2023 Unity Technologies and the glTFast authors
// SPDX-License-Identifier: Apache-2.0
using System;
using UnityEngine;
namespace GLTFast.Export
{
///
/// Provides the default material export
///
public static class MaterialExport
{
static IMaterialExport s_MaterialExport;
///
/// Provides the default material exporter
///
/// Default material export
/// Is thrown when the default material export couldn't be determined based on the current render pipeline.
public static IMaterialExport GetDefaultMaterialExport()
{
if (s_MaterialExport == null)
{
var renderPipeline = RenderPipelineUtils.RenderPipeline;
switch (renderPipeline)
{
case RenderPipeline.BuiltIn:
case RenderPipeline.Universal:
#if UNITY_SHADER_GRAPH
s_MaterialExport = MetaMaterialExportShaderGraphs<
StandardMaterialExport,
GltfShaderGraphMaterialExporter
>.Instance;
#else
s_MaterialExport = MetaMaterialExportBuiltIn.Instance;
#endif
break;
#if USING_HDRP
case RenderPipeline.HighDefinition:
s_MaterialExport = MetaMaterialExportShaderGraphs<
HighDefinitionMaterialExport,
GltfHdrpMaterialExporter
>.Instance;
break;
#endif
default:
throw new InvalidOperationException($"Could not determine default MaterialExport (render pipeline {renderPipeline})");
}
}
return s_MaterialExport;
}
///
/// Adds an ImageExport to the glTF.
/// No conversions or channel swizzling
///
/// glTF to add the image to.
/// Texture generator to be added
/// Resulting texture index.
/// True if the texture was added, false otherwise.
internal static bool AddImageExport(IGltfWritable gltf, ImageExportBase imageExport, out int textureId)
{
var imageId = gltf.AddImage(imageExport);
if (imageId < 0)
{
textureId = -1;
return false;
}
var samplerId = gltf.AddSampler(imageExport.FilterMode, imageExport.WrapModeU, imageExport.WrapModeV);
textureId = gltf.AddTexture(imageId, samplerId);
return true;
}
}
}