Texture inheritance for materials, also script access

This commit is contained in:
Simon Lübeß
2025-03-01 00:03:38 +01:00
parent 824c19c0b2
commit b5088329f5
13 changed files with 470 additions and 82 deletions
+22
View File
@@ -1,4 +1,5 @@
using System.Diagnostics.SymbolStore;
using GlitchyEngine.Core;
using GlitchyEngine.Math;
namespace GlitchyEngine.Graphics;
@@ -20,4 +21,25 @@ public class Material : Asset
{
ScriptGlue.Material_ResetVariable(_uuid, name);
}
public void SetTexture(string name, Texture? texture)
{
ScriptGlue.Material_SetTexture(_uuid, name, texture?._uuid ?? UUID.Zero);
}
public Texture? GetTexture(string name)
{
ScriptGlue.Material_GetTexture(_uuid, name, out UUID textureId);
// TODO: Support different texture types?
return new Texture
{
_uuid = textureId
};
}
public void ResetTexture(string name)
{
ScriptGlue.Material_ResetTexture(_uuid, name);
}
}
+34 -3
View File
@@ -8,11 +8,16 @@ namespace GlitchyEngine.Graphics;
public class MeshRenderer : Component
{
/// <summary>
/// Gets or sets the Material of this <see cref="MeshRenderer"/>.
/// Gets or sets the instance Material of this <see cref="MeshRenderer"/>.
/// </summary>
/// <remarks>
/// If you get the <see cref="Material"/> and it is not yet a runtime-instance,
/// a new runtime-instance will be created and returned in its place.
/// If you get the <see cref="GlitchyEngine.Graphics.Material"/> and it is not yet a runtime-instance,
/// a new runtime-instance will be created and returned in its place. If you want to get the actual material instance,
/// use <see cref="SharedMaterial"/> instead.
/// <para>
/// <b>Note:</b> While the behaviour differs for getting <see cref="SharedMaterial"/> and <see cref="Material"/>,
/// the setter behaves identical for both properties.
/// </para>
/// </remarks>
public Material Material
{
@@ -24,4 +29,30 @@ public class MeshRenderer : Component
}
set => ScriptGlue.MeshRenderer_SetMaterial(_uuid, value._uuid);
}
/// <summary>
/// Gets or sets the shared Material of this <see cref="MeshRenderer"/>.
/// </summary>
/// <remarks>
/// <para>
/// In contrast to the <see cref="Material"/>-property this will not create a new runtime-instance and instead
/// always return the actual Material-Asset.
/// Making changes to the instance returned by this property will have global effect.
/// <see cref="GlitchyEngine.Graphics.Material"/> is used (and obviously instances/children of it).
/// </para>
/// <para>
/// <b>Note:</b> While the behaviour differs for getting <see cref="SharedMaterial"/> and <see cref="Material"/>,
/// the setter behaves identical for both properties.
/// </para>
/// </remarks>
public Material SharedMaterial
{
get
{
ScriptGlue.MeshRenderer_GetSharedMaterial(_uuid, out UUID materialHandle);
return new Material { _uuid = materialHandle };
}
set => ScriptGlue.MeshRenderer_SetMaterial(_uuid, value._uuid);
}
}
+6
View File
@@ -0,0 +1,6 @@
namespace GlitchyEngine.Graphics;
public class Texture : Asset
{
}