using System; namespace Raylib_cs; internal static unsafe class MeshExtensions { /// Allocate mesh vertices public static void AllocVertices(ref this Mesh mesh) { mesh.Vertices = Raylib.New(3 * mesh.VertexCount); } /// Allocate mesh texcoords public static void AllocTexcoords(ref this Mesh mesh) { mesh.TexCoords = Raylib.New(2 * mesh.VertexCount); } /// Allocate mesh texcoords2 public static void AllocTexcoords2(ref this Mesh mesh) { mesh.TexCoords2 = Raylib.New(2 * mesh.VertexCount); } /// Allocate mesh normals public static void AllocNormals(ref this Mesh mesh) { mesh.Normals = Raylib.New(3 * mesh.VertexCount); } /// Allocate mesh tangents public static void AllocTangents(ref this Mesh mesh) { mesh.Tangents = Raylib.New(4 * mesh.VertexCount); } /// Allocate mesh colors public static void AllocColors(ref this Mesh mesh) { mesh.Colors = Raylib.New(4 * mesh.VertexCount); } /// Allocate mesh indices public static void AllocIndices(ref this Mesh mesh) { mesh.Indices = Raylib.New(3 * mesh.TriangleCount); } /// Access mesh vertices public static Span VerticesAs(this Mesh mesh) where T : unmanaged { return new(mesh.Vertices, 3 * mesh.VertexCount * sizeof(float) / sizeof(T)); } /// Access mesh texcoords public static Span TexcoordsAs(this Mesh mesh) where T : unmanaged { return new(mesh.TexCoords, 2 * mesh.VertexCount * sizeof(float) / sizeof(T)); } /// Access mesh texcoords2 public static Span Texcoords2As(this Mesh mesh) where T : unmanaged { return new(mesh.TexCoords2, 2 * mesh.VertexCount * sizeof(float) / sizeof(T)); } /// Access mesh normals public static Span NormalsAs(this Mesh mesh) where T : unmanaged { return new(mesh.Normals, 3 * mesh.VertexCount * sizeof(float) / sizeof(T)); } /// Access mesh tangents public static Span TangentsAs(this Mesh mesh) where T : unmanaged { return new(mesh.Tangents, 4 * mesh.VertexCount * sizeof(float) / sizeof(T)); } /// Access mesh colors public static Span ColorsAs(this Mesh mesh) where T : unmanaged { return new(mesh.Colors, 4 * mesh.VertexCount * sizeof(byte) / sizeof(T)); } /// Access mesh indices public static Span IndicesAs(this Mesh mesh) where T : unmanaged { return new(mesh.Indices, 3 * mesh.TriangleCount * sizeof(ushort) / sizeof(T)); } }