mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Interact with Materials from scripts
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user