Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/publish-core.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Publish NuGet Package

on:
push:
branches:
- main

jobs:
publish:
runs-on: windows-latest # Use Windows to support .NET SDK easily

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x' # TODO: Create variable out of this

# TODO: Quality gates (Unit tests, sonar cloud?)

- name: Restore dependencies
run: dotnet restore

- name: Build project
run: dotnet build --configuration Release --no-restore

# TODO: Create installer for launcher and editor bundle

- name: Pack NuGet package
run: dotnet pack --configuration Release --no-build --output Core/bin/Release/

- name: Publish to NuGet
run: dotnet nuget push "Core/bin/Release/SharpEngine.Core.NET.1.0.0.nupkg" --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.PUBLISH_NUGET_PACKAGE }} --skip-duplicate

# TODO: Publish the NuGet package to GitHub.
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.PUBLISH_REPO_PACKAGE }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false

- name: Upload NuGet package to GitHub Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.PUBLISH_REPO_PACKAGE }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: Core/bin/Release/SharpEngine.Core.NET.1.0.0.nupkg
asset_name: SharpEngine.Core.NET.1.0.0.nupkg
asset_content_type: application/zip
14 changes: 10 additions & 4 deletions Core/Entities/GameObject.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using SharpEngine.Core.Attributes;
using SharpEngine.Core.Entities.Properties;
using SharpEngine.Core.Entities.Properties.Meshes;
using SharpEngine.Core.Scenes;
using SharpEngine.Core.Shaders;
using SharpEngine.Core.Textures;

using Silk.NET.OpenGL;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace SharpEngine.Core.Entities;
Expand All @@ -16,7 +19,10 @@ public class GameObject : SceneNode
/// <summary>
/// Initializes a new instance of the <see cref="GameObject"/>.
/// </summary>
public GameObject() { }
public GameObject()
{
//BoundingBox = BoundingBox.CalculateBoundingBox(Transform);
}

/// <summary>
/// Initializes a new instance of the <see cref="GameObject"/> with specified textures and shaders.
Expand All @@ -28,18 +34,18 @@ public GameObject() { }
public GameObject(string diffuseMapFile, string specularMapFile, string vertShaderFile, string fragShaderFile)
{
Material.DiffuseMap = TextureService.Instance.LoadTexture(diffuseMapFile);

// TODO: Make specular map optional
Material.SpecularMap = TextureService.Instance.LoadTexture(specularMapFile);
Material.Shader = ShaderService.Instance.LoadShader(vertShaderFile, fragShaderFile, "lighting");

BoundingBox = BoundingBox.CalculateBoundingBox(Transform);
}

// TODO: Cleanup these properties

/// <summary>
/// Gets or sets the mesh of the game object.
/// </summary>
public Mesh Mesh { get; set; }
public List<Mesh> Mesh { get; set; } = [];

/// <summary>
/// Gets or sets the material of the game object.
Expand Down
112 changes: 0 additions & 112 deletions Core/Entities/Properties/Mesh.cs

This file was deleted.

30 changes: 30 additions & 0 deletions Core/Entities/Properties/Meshes/Mesh.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using SharpEngine.Core.Attributes;

namespace SharpEngine.Core.Entities.Properties.Meshes;

/// <summary>
/// Represents a game object mesh.
/// </summary>
public class Mesh
{
/// <summary>Gets or sets a indetifying name for the mesh.</summary>
public string Name { get; set; } = "New Mesh";

/// <summary>
/// Gets or sets the mesh vertices.
/// </summary>
[Inspector(DisplayInInspector = false)]
public float[] Vertices { get; set; } = [];

/// <summary>
/// Gets or sets the mesh normals.
/// </summary>
[Inspector(DisplayInInspector = false)]
public float[] Normals { get; set; } = [];

/// <summary>
/// Gets or sets the mesh texture UV coordinates.
/// </summary>
[Inspector(DisplayInInspector = false)]
public float[] TextureCoordinates { get; set; } = [];
}
40 changes: 40 additions & 0 deletions Core/Entities/Properties/Meshes/MeshExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Collections.Generic;

namespace SharpEngine.Core.Entities.Properties.Meshes;

/// <summary>
/// Contains extension methods for handling meshes.
/// </summary>
public static class MeshExtensions
{
/// <summary>
/// Gets the vertices of a mesh.
/// </summary>
/// <param name="mesh">The mesh who's vertices should be retrieved.</param>
/// <returns>The vertex data of the mesh (vertex, normal, uv).</returns>
public static float[] GetVertices(this Mesh mesh)
{
var vertices = new List<float>();

// The current implementation assumes that the mesh has the same amount of vertices, normals and texture coordinates in a specific order.
for (int i = 0; i < mesh.Vertices.Length / 3; i++)
{
var vertexIndex = i * 3;

vertices.Add(mesh.Vertices[vertexIndex]);
vertices.Add(mesh.Vertices[vertexIndex + 1]);
vertices.Add(mesh.Vertices[vertexIndex + 2]);

var normalIndex = i * 3;
vertices.Add(mesh.Normals[normalIndex]);
vertices.Add(mesh.Normals[normalIndex + 1]);
vertices.Add(mesh.Normals[normalIndex + 2]);

var texCoordIndex = i * 2;
vertices.Add(mesh.TextureCoordinates[texCoordIndex]);
vertices.Add(mesh.TextureCoordinates[texCoordIndex + 1]);
}

return [.. vertices];
}
}
47 changes: 47 additions & 0 deletions Core/Entities/Properties/Meshes/MeshService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Silk.NET.OpenGL;
using System.Collections.Generic;

namespace SharpEngine.Core.Entities.Properties.Meshes;

/// <summary>
/// Represents a service that loads meshes into the GPU.
/// </summary>
public class MeshService
{
/// <summary>A global instance of the service.</summary>
public static readonly MeshService Instance = new();

private readonly Dictionary<string, Mesh> Meshes = [];

private MeshService() { }

/// <summary>
/// Loads a mesh into the mesh cache.
/// </summary>
/// <param name="identifier">Used to cache the loaded mesh.</param>
/// <param name="mesh">The mesh that should be stored in to the GPU buffer.</param>
/// <returns>The loaded mesh.</returns>
public Mesh LoadMesh(string identifier, Mesh mesh)
{
if (Meshes.TryGetValue(identifier, out var cachedMesh))
return cachedMesh;

var meshData = mesh.GetVertices();

var vertexBufferObject = Window.GL.GenBuffer();
Window.GL.BindBuffer(GLEnum.ArrayBuffer, vertexBufferObject);

unsafe
{
fixed (float* meshDataPtr = meshData)
{
Window.GL.BufferData(GLEnum.ArrayBuffer, (uint)meshData.Length * sizeof(float), meshDataPtr, GLEnum.StaticDraw);
}
}

Meshes.Add(identifier, mesh);
return mesh;
}

// TODO: #3 & #2 Load mesh from file
}
12 changes: 8 additions & 4 deletions Core/Entities/UIElement.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using SharpEngine.Core.Entities.Properties;
using SharpEngine.Core.Entities.Properties.Meshes;
using SharpEngine.Core.Scenes;
using SharpEngine.Core.Shaders;

using Silk.NET.OpenGL;
using System.Threading.Tasks;

Expand All @@ -14,7 +16,7 @@ public class UIElement : SceneNode
/// <summary>
/// Initializes a new instance of <see cref="UIElement"/>.
/// </summary>
/// <param name="name"></param>
/// <param name="name">The name of the UI element.</param>
public UIElement(string name)
{
Name = name;
Expand All @@ -32,6 +34,7 @@ public UIElement(string name)
};

// TODO: Use actual mesh
/// <summary>Gets or sets the mesh of the UI element.</summary>
public Mesh Mesh { get; set; }

private readonly float[] _vertices =
Expand Down Expand Up @@ -83,10 +86,11 @@ private unsafe void InitializeBuffers()
public override Task Render()
{
Window.GL.BindVertexArray(_vertexArrayObject);

_uIShader.Shader.SetMatrix4(ShaderAttributes.Model, Transform.ModelMatrix);

Window.GL.DrawElements(PrimitiveType.Triangles, (uint)_indices.Length, DrawElementsType.UnsignedInt, 0);

uint a = 0;
Window.GL.DrawElements(PrimitiveType.Triangles, (uint)_indices.Length, DrawElementsType.UnsignedInt, ref a);

return Task.CompletedTask;
}
Expand Down
2 changes: 1 addition & 1 deletion Core/Primitives/Cube.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using SharpEngine.Core.Entities.Properties;
using SharpEngine.Core.Entities.Properties.Meshes;

namespace SharpEngine.Core.Primitives;

Expand Down
2 changes: 1 addition & 1 deletion Core/Primitives/Plane.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using SharpEngine.Core.Entities.Properties;
using SharpEngine.Core.Entities.Properties.Meshes;

namespace SharpEngine.Core.Primitives;

Expand Down
Loading