Interact with Materials from scripts

This commit is contained in:
Simon Lübeß
2025-02-14 11:54:07 +01:00
parent e5437c6ff6
commit aaed4199d3
24 changed files with 739 additions and 64 deletions
+22
View File
@@ -0,0 +1,22 @@
using GlitchyEngine.Core;
namespace GlitchyEngine.Graphics;
/// <summary>
/// The base class for all assets.
/// </summary>
public class Asset : EngineObject
{
/// <summary>
/// Gets or sets the Identifier of the asset.
/// </summary>
public string Identifier
{
get
{
ScriptGlue.Asset_GetIdentifier(_uuid, out string identifier);
return identifier;
}
set => ScriptGlue.Asset_SetIdentifier(_uuid, value);
}
}
+1 -1
View File
@@ -26,7 +26,7 @@ public class CircleRenderer : Component
/// <summary>
/// Gets or sets the UV transform for the texture. XY are an offset, ZW are scaling
/// </summary>
public float4 UvTransform
public float4 UVTransform
{
get
{
+15
View File
@@ -0,0 +1,15 @@
using System.Diagnostics.SymbolStore;
using GlitchyEngine.Math;
namespace GlitchyEngine.Graphics;
public class Material : Asset
{
public void SetVariable(string name, float4 value)
{
unsafe
{
ScriptGlue.Material_SetVariable(_uuid, name, ScriptGlue.ShaderVariableType.Float, 1, 4, 1, &value, sizeof(float4));
}
}
}
+12
View File
@@ -0,0 +1,12 @@
using GlitchyEngine.Core;
namespace GlitchyEngine.Graphics;
/// <summary>
/// Holds a reference to a Mesh.
/// Can be used in combination with a <see cref="MeshRenderer"/> on the same <see cref="Entity"/> to render the mesh.
/// </summary>
public class Mesh : Component
{
}
+23
View File
@@ -0,0 +1,23 @@
using GlitchyEngine.Core;
namespace GlitchyEngine.Graphics;
/// <summary>
/// Renders a Mesh. The Mesh can be specified by adding a <see cref="Mesh"/> component to the same <see cref="Entity"/>.
/// </summary>
public class MeshRenderer : Component
{
/// <summary>
/// Gets or sets the Material of this <see cref="MeshRenderer"/>.
/// </summary>
public Material Material
{
get
{
ScriptGlue.MeshRenderer_GetMaterial(_uuid, out UUID materialHandle);
return new Material { _uuid = materialHandle };
}
set => ScriptGlue.MeshRenderer_SetMaterial(_uuid, value._uuid);
}
}
+52
View File
@@ -0,0 +1,52 @@
using GlitchyEngine.Core;
using GlitchyEngine.Math;
namespace GlitchyEngine.Graphics;
/// <summary>
/// Component that renders a sprite.
/// </summary>
public class SpriteRenderer : Component
{
// TODO: Texture2D/Sprite
/// <summary>
/// Gets or sets the tint color.
/// </summary>
public ColorRGBA Color
{
get
{
ScriptGlue.SpriteRenderer_GetColor(_uuid, out ColorRGBA color);
return color;
}
set => ScriptGlue.SpriteRenderer_SetColor(_uuid, value);
}
/// <summary>
/// Gets or sets the UV-transform.
/// </summary>
public UVTransform UVTransform
{
get
{
ScriptGlue.SpriteRenderer_GetUvTransform(_uuid, out UVTransform uvTransform);
return uvTransform;
}
set => ScriptGlue.SpriteRenderer_SetUvTransform(_uuid, value);
}
/// <summary>
/// Gets or sets the Material of this SpriteRenderer.
/// </summary>
public Material Material
{
get
{
ScriptGlue.SpriteRenderer_GetMaterial(_uuid, out UUID materialHandle);
return new Material { _uuid = materialHandle };
}
set => ScriptGlue.SpriteRenderer_SetMaterial(_uuid, value._uuid);
}
}
+39
View File
@@ -0,0 +1,39 @@
using System.Runtime.InteropServices;
using GlitchyEngine.Math;
namespace GlitchyEngine.Graphics;
/// <summary>
/// Stores transformations that can be applied to UV-Coordinates.
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack=1)]
public struct UVTransform
{
/// <summary>
/// The offset that will be added to the UV-Coordinate.
/// </summary>
public float2 Offset;
/// <summary>
/// The scaling that will be applied to the UV-Coordinate.
/// </summary>
public float2 Scale;
/// <summary>
/// Creates a new instance of <see cref="UVTransform"/> with the given scale and offset.
/// </summary>
/// <param name="offset"><inheritdoc cref="Offset"/></param>
/// <param name="scale"><inheritdoc cref="Scale"/></param>
public UVTransform(float2 offset, float2 scale)
{
Offset = offset;
Scale = scale;
}
/// <summary>
/// Transforms the given uv-coordinate.
/// </summary>
public float2 Transform(float2 uvCoordinate)
{
return Offset + uvCoordinate * Scale;
}
}