Updated Sphere generation
Some checks failed
Gitea Actions Demo / Scan the project (push) Failing after 7s
Some checks failed
Gitea Actions Demo / Scan the project (push) Failing after 7s
This commit is contained in:
36
Nebulix/ArrayExtensions.cs
Normal file
36
Nebulix/ArrayExtensions.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System.Numerics;
|
||||
using Silk.NET.Maths;
|
||||
|
||||
namespace Nebulix
|
||||
{
|
||||
public static class ArrayExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Copies the given arrays to the start of this array. The order of <paramref name="arrays"/> is preserved
|
||||
/// </summary>
|
||||
/// <param name="arrays">The arrays copied into this array</param>
|
||||
public static void CopyFrom(this Array array, params Array[] arrays)
|
||||
{
|
||||
int lastIndex = 0;
|
||||
for (int i = 0; i < arrays.Length; i++)
|
||||
{
|
||||
arrays[i].CopyTo(array, lastIndex);
|
||||
lastIndex += arrays[i].Length;
|
||||
}
|
||||
}
|
||||
|
||||
public static T[] ExtractComponents<T>(this Vector3D<T>[] array) where T : unmanaged, IFormattable, IEquatable<T>, IComparable<T>
|
||||
{
|
||||
T[] result = new T[array.Length * 3]; // * 3 cause a Vector3D has 3 components
|
||||
int resultIdx = 0;
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
result[resultIdx] = array[i].X;
|
||||
result[resultIdx + 1] = array[i].Y;
|
||||
result[resultIdx + 2] = array[i].Z;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
@ -5,19 +5,29 @@ namespace Nebulix.Rendering
|
||||
public sealed class Mesh
|
||||
{
|
||||
public float[] Vertices { get => vertices; set { vertices = value; regenerate = true; } }
|
||||
public float[] Indices { get => indices; set { indices = value; regenerate = true; } }
|
||||
public float[] Normals { get => normals; }
|
||||
public nuint[] Indices { get => indices; set { indices = value; regenerate = true; } }
|
||||
|
||||
private uint vao = 0, vbo = 0, ebo = 0;
|
||||
private bool regenerate = true;
|
||||
|
||||
private float[] vertices = [];
|
||||
private float[] indices = [];
|
||||
private nuint[] indices = [];
|
||||
private float[] normals = [];
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
vertices = [];
|
||||
indices = [];
|
||||
}
|
||||
|
||||
// getting called by "Engine" which currently is in other assembly, meaning I probably need to make this public
|
||||
internal void Use(GL gl)
|
||||
public void CalculateNormals()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
// getting called by "Engine" which currently is in another assembly, meaning I probably need to make this public
|
||||
// needs to be change for the real engine
|
||||
public void Use(GL gl)
|
||||
{
|
||||
if (regenerate) Generate(gl);
|
||||
|
||||
@ -44,7 +54,7 @@ namespace Nebulix.Rendering
|
||||
gl.BindBuffer(BufferTargetARB.ArrayBuffer, vbo);
|
||||
gl.BufferData(BufferTargetARB.ArrayBuffer, (nuint)(data.Length * sizeof(float)), data, BufferUsageARB.StaticDraw);
|
||||
|
||||
ReadOnlySpan<float> indicesData = new(indices);
|
||||
ReadOnlySpan<nuint> indicesData = new(indices);
|
||||
gl.BindBuffer(BufferTargetARB.ElementArrayBuffer, ebo);
|
||||
gl.BufferData(BufferTargetARB.ElementArrayBuffer, (nuint)(indicesData.Length * sizeof(uint)), indicesData, BufferUsageARB.StaticDraw);
|
||||
|
||||
|
Reference in New Issue
Block a user