rj-action-library/Runtime/Shading/Materials.cs

61 lines
1.2 KiB
C#

using Godot;
using System.Reflection;
using System.Collections.Generic;
namespace Rokojori
{
public class Materials
{
public static void Set( Node node, Material material, int index = 0 )
{
if ( node is MeshInstance3D )
{
var mi = (MeshInstance3D) node;
mi.SetSurfaceOverrideMaterial( index, material );
if ( index == 0 && mi.MaterialOverride != null )
{
mi.MaterialOverride = null;
}
return;
}
if ( node is CsgPrimitive3D )
{
ReflectionHelper.SetMemberValue( node, "material", material );
var cp = (GpuParticles3D) node;
cp.ProcessMaterial = material;
if ( cp.MaterialOverride != null )
{
cp.MaterialOverride = null;
}
return;
}
if ( node is GpuParticles3D )
{
var gp = (GpuParticles3D) node;
gp.ProcessMaterial = material;
if ( gp.MaterialOverride != null )
{
gp.MaterialOverride = null;
}
}
if ( node is GeometryInstance3D )
{
var gi = (GeometryInstance3D) node;
gi.MaterialOverride = material;
return;
}
}
}
}