Watch
2
0
Fork
You've already forked raylib-cs
0
raylib-cs/Raylib-cs/types/Material.cs
Matorio b84a0d4f12 Merging
Added new extension "byte.Lerp".
Added new extension "Log" for "TraceLogLevel".
Constructors on Color no longer just truncate the float value, but also round it (+ 0.5f).
New static method on Color, "Color.Lerp".
Added static method "FromHSV" to Color.
Added new getter method "GetHSV" on Color.
Added index security on the FilePathList indexer.
Merged Rectangle extensions with the type itself as read-only methods.
Merged Image extensions with the type itself.
Merged Texture2D extensions with the type itself.
New file "Raymath.Utils" with some useful methods taken from Unity.
Added "MoveTowards" extensions to RaylibExtensions.
Added "TranslateLocal" and "TranslateGlobal" to Transform.
Added "Load", "Export", "ExportAsCode", "Format", "Crop", and "Unload" shortcut methods to Wave.
Added "IsValid" property to Wave, Texture2D, Sound, Shader, RenderTexture2D, Music, Image, Model, Material, Font, and AudioStream.
Added "IsPlaying" and "IsProcessed" properties to AudioStream.
Added "Load", "Play", "Stop", "Pause", "Resume", "SetBufferSizeDefault", "SetPan", "SetPitch", "SetVolume", and "Unload" shortcut methods to AudioStream.
Added "Load", "Export", and "Unload" methods to AutomationEventList.
Added "Default" property to Font.
Added "Load", "GetMaterial", "GetTexture", "SetTexture", "SetShader", and "Unload" methods to material.
Added "Draw", "DrawInstanced", "Export", "ExportAsCode", "Upload", and "Unload" methods to Mesh.
Added "Load", "LoadFromMesh", "Unload", and a lot of "Draw" overloads.
Added "Load", "Play", "Pause", "Stop", "SetPan", "SetPitch", "SetVolume", "Seek", and "Unload" methods to Music.
Added "Load" and "Unload" methods to RenderTexture2D.
Added "Load", "LoadFromMemory", "GetLocationAttrib", "SetValue", "SetTexture", "SetMatrix", and "Unload" methods to Shader.
Removed unnecessary "partial" declarations.
2025-07-17 03:14:57 -05:00

141 lines
3 KiB
C#

using System.Runtime.InteropServices;
namespace Raylib_cs;
/// <summary>
/// Material map index
/// </summary>
public enum MaterialMapIndex
{
/// <summary>
/// NOTE: Same as MATERIAL_MAP_DIFFUSE
/// </summary>
Albedo = 0,
/// <summary>
/// NOTE: Same as MATERIAL_MAP_SPECULAR
/// </summary>
Metalness,
Normal,
Roughness,
Occlusion,
Emission,
Height,
/// <summary>
/// NOTE: Uses GL_TEXTURE_CUBE_MAP
/// </summary>
Cubemap,
/// <summary>
/// NOTE: Uses GL_TEXTURE_CUBE_MAP
/// </summary>
Irradiance,
/// <summary>
/// NOTE: Uses GL_TEXTURE_CUBE_MAP
/// </summary>
Prefilter,
Brdf,
Diffuse = Albedo,
Specular = Metalness,
}
/// <summary>
/// Material texture map
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct MaterialMap
{
/// <summary>
/// Material map texture
/// </summary>
public Texture2D Texture;
/// <summary>
/// Material map color
/// </summary>
public Color Color;
/// <summary>
/// Material map value
/// </summary>
public float Value;
}
/// <summary>
/// Material type (generic)
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public unsafe struct Material
{
/// <summary>
/// Material shader
/// </summary>
public Shader Shader;
//TODO: convert
/// <summary>
/// Material maps
/// </summary>
public MaterialMap* Maps;
/// <summary>
/// Material generic parameters (if required)
/// </summary>
public fixed float Param[4];
public readonly CBool IsValid => Raylib.IsMaterialValid(this);
/// <summary>
/// Load default material
/// </summary>
public static Material Load()
{
return Raylib.LoadMaterialDefault();
}
/// <summary>
/// Load materials from model file
/// </summary>
public static Material[] Load(string fileName)
{
using AnsiBuffer buffer = fileName.ToAnsiBuffer();
int count = 0;
Material* materials = Raylib.LoadMaterials(buffer.AsPointer(), &count);
Material[] output = new Material[count];
for (int i = 0; i < count; i++)
{
output[i] = materials[i];
}
return output;
}
public static Material GetMaterial(ref Model model, int materialIndex)
{
return Raylib.GetMaterial(ref model, materialIndex);
}
public static Texture2D GetTexture(ref Model model, int materialIndex, MaterialMapIndex mapIndex)
{
return Raylib.GetMaterialTexture(ref model, materialIndex, mapIndex);
}
public void SetTexture(MaterialMapIndex mapIndex, Texture2D texture)
{
Raylib.SetMaterialTexture(ref this, mapIndex, texture);
}
public static void SetShader(ref Model model, int materialIndex, ref Shader shader)
{
Raylib.SetMaterialShader(ref model, materialIndex, ref shader);
}
public void Unload()
{
Raylib.UnloadMaterial(this);
}
}