remove MeshExtentions class
This commit is contained in:
parent
88ea2f1f08
commit
3518ffa3f6
2 changed files with 107 additions and 90 deletions
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Raylib_cs;
|
||||
|
|
@ -65,6 +66,112 @@ public unsafe partial struct Mesh
|
|||
/// </summary>
|
||||
public ushort* Indices = default;
|
||||
|
||||
/// <summary>
|
||||
/// Allocate <see cref="Vertices"/>
|
||||
/// </summary>
|
||||
public void AllocVertices()
|
||||
{
|
||||
Vertices = Raylib.New<float>(3 * VertexCount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allocate <see cref="TexCoords"/>
|
||||
/// </summary>
|
||||
public void AllocTexCoords()
|
||||
{
|
||||
TexCoords = Raylib.New<float>(2 * VertexCount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allocate <see cref="TexCoords2"/>
|
||||
/// </summary>
|
||||
public void AllocTexCoords2()
|
||||
{
|
||||
TexCoords2 = Raylib.New<float>(2 * VertexCount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allocate <see cref="Normals"/>
|
||||
/// </summary>
|
||||
public void AllocNormals()
|
||||
{
|
||||
Normals = Raylib.New<float>(3 * VertexCount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allocate <see cref="Tangents"/>
|
||||
/// </summary>
|
||||
public void AllocTangents()
|
||||
{
|
||||
Tangents = Raylib.New<float>(4 * VertexCount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allocate <see cref="Colors"/>
|
||||
/// </summary>
|
||||
public void AllocColors()
|
||||
{
|
||||
Colors = Raylib.New<byte>(4 * VertexCount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allocate <see cref="Indices"/>
|
||||
/// </summary>
|
||||
public void AllocIndices()
|
||||
{
|
||||
Indices = Raylib.New<ushort>(3 * TriangleCount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Access <see cref="Vertices"/>
|
||||
/// </summary>
|
||||
public readonly Span<T> VerticesAs<T>() where T : unmanaged
|
||||
{
|
||||
return new(Vertices, 3 * VertexCount * sizeof(float) / sizeof(T));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Access <see cref="TexCoords"/>
|
||||
/// </summary>
|
||||
public readonly Span<T> TexCoordsAs<T>() where T : unmanaged
|
||||
{
|
||||
return new(TexCoords, 2 * VertexCount * sizeof(float) / sizeof(T));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Access <see cref="TexCoords2"/>
|
||||
/// </summary>
|
||||
public readonly Span<T> TexCoords2As<T>() where T : unmanaged
|
||||
{
|
||||
return new(TexCoords2, 2 * VertexCount * sizeof(float) / sizeof(T));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Access <see cref="Normals"/>
|
||||
/// </summary>
|
||||
public readonly Span<T> NormalsAs<T>() where T : unmanaged
|
||||
{
|
||||
return new(Normals, 3 * VertexCount * sizeof(float) / sizeof(T));
|
||||
}
|
||||
|
||||
/// <summary>Access <see cref="Tangents"/></summary>
|
||||
public readonly Span<T> TangentsAs<T>() where T : unmanaged
|
||||
{
|
||||
return new(Tangents, 4 * VertexCount * sizeof(float) / sizeof(T));
|
||||
}
|
||||
|
||||
/// <summary>Access <see cref="Colors"/></summary>
|
||||
public readonly Span<T> ColorsAs<T>() where T : unmanaged
|
||||
{
|
||||
return new(Colors, 4 * VertexCount * sizeof(byte) / sizeof(T));
|
||||
}
|
||||
|
||||
/// <summary>Access <see cref="Indices"/></summary>
|
||||
public readonly Span<T> IndicesAs<T>() where T : unmanaged
|
||||
{
|
||||
return new(Indices, 3 * TriangleCount * sizeof(ushort) / sizeof(T));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Animation vertex data
|
||||
|
|
|
|||
|
|
@ -1,90 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace Raylib_cs;
|
||||
|
||||
internal static unsafe class MeshExtensions
|
||||
{
|
||||
/// <summary>Allocate mesh vertices</summary>
|
||||
public static void AllocVertices(ref this Mesh mesh)
|
||||
{
|
||||
mesh.Vertices = Raylib.New<float>(3 * mesh.VertexCount);
|
||||
}
|
||||
|
||||
/// <summary>Allocate mesh texcoords</summary>
|
||||
public static void AllocTexcoords(ref this Mesh mesh)
|
||||
{
|
||||
mesh.TexCoords = Raylib.New<float>(2 * mesh.VertexCount);
|
||||
}
|
||||
|
||||
/// <summary>Allocate mesh texcoords2</summary>
|
||||
public static void AllocTexcoords2(ref this Mesh mesh)
|
||||
{
|
||||
mesh.TexCoords2 = Raylib.New<float>(2 * mesh.VertexCount);
|
||||
}
|
||||
|
||||
/// <summary>Allocate mesh normals</summary>
|
||||
public static void AllocNormals(ref this Mesh mesh)
|
||||
{
|
||||
mesh.Normals = Raylib.New<float>(3 * mesh.VertexCount);
|
||||
}
|
||||
|
||||
/// <summary>Allocate mesh tangents</summary>
|
||||
public static void AllocTangents(ref this Mesh mesh)
|
||||
{
|
||||
mesh.Tangents = Raylib.New<float>(4 * mesh.VertexCount);
|
||||
}
|
||||
|
||||
/// <summary>Allocate mesh colors</summary>
|
||||
public static void AllocColors(ref this Mesh mesh)
|
||||
{
|
||||
mesh.Colors = Raylib.New<byte>(4 * mesh.VertexCount);
|
||||
}
|
||||
|
||||
/// <summary>Allocate mesh indices</summary>
|
||||
public static void AllocIndices(ref this Mesh mesh)
|
||||
{
|
||||
mesh.Indices = Raylib.New<ushort>(3 * mesh.TriangleCount);
|
||||
}
|
||||
|
||||
/// <summary>Access mesh vertices</summary>
|
||||
public static Span<T> VerticesAs<T>(this Mesh mesh) where T : unmanaged
|
||||
{
|
||||
return new(mesh.Vertices, 3 * mesh.VertexCount * sizeof(float) / sizeof(T));
|
||||
}
|
||||
|
||||
/// <summary>Access mesh texcoords</summary>
|
||||
public static Span<T> TexcoordsAs<T>(this Mesh mesh) where T : unmanaged
|
||||
{
|
||||
return new(mesh.TexCoords, 2 * mesh.VertexCount * sizeof(float) / sizeof(T));
|
||||
}
|
||||
|
||||
/// <summary>Access mesh texcoords2</summary>
|
||||
public static Span<T> Texcoords2As<T>(this Mesh mesh) where T : unmanaged
|
||||
{
|
||||
return new(mesh.TexCoords2, 2 * mesh.VertexCount * sizeof(float) / sizeof(T));
|
||||
}
|
||||
|
||||
/// <summary>Access mesh normals</summary>
|
||||
public static Span<T> NormalsAs<T>(this Mesh mesh) where T : unmanaged
|
||||
{
|
||||
return new(mesh.Normals, 3 * mesh.VertexCount * sizeof(float) / sizeof(T));
|
||||
}
|
||||
|
||||
/// <summary>Access mesh tangents</summary>
|
||||
public static Span<T> TangentsAs<T>(this Mesh mesh) where T : unmanaged
|
||||
{
|
||||
return new(mesh.Tangents, 4 * mesh.VertexCount * sizeof(float) / sizeof(T));
|
||||
}
|
||||
|
||||
/// <summary>Access mesh colors</summary>
|
||||
public static Span<T> ColorsAs<T>(this Mesh mesh) where T : unmanaged
|
||||
{
|
||||
return new(mesh.Colors, 4 * mesh.VertexCount * sizeof(byte) / sizeof(T));
|
||||
}
|
||||
|
||||
/// <summary>Access mesh indices</summary>
|
||||
public static Span<T> IndicesAs<T>(this Mesh mesh) where T : unmanaged
|
||||
{
|
||||
return new(mesh.Indices, 3 * mesh.TriangleCount * sizeof(ushort) / sizeof(T));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue