using System;
using System.Numerics;
using System.Runtime.InteropServices;
namespace Raylib_cs;
///
/// Bone information
///
[StructLayout(LayoutKind.Sequential)]
public unsafe struct BoneInfo
{
///
/// Bone name (char[32])
///
public fixed sbyte Name[32];
///
/// Bone parent
///
public int Parent;
public string NameToString()
{
fixed (sbyte* name = Name)
{
return Utf8StringUtils.GetUTF8String(name);
}
}
}
///
/// Skeleton, animation bones hierarchy
///
[StructLayout(LayoutKind.Sequential)]
public unsafe struct ModelSkeleton
{
///
/// Number of bones
///
public int BoneCount;
///
/// Bones information (skeleton)
///
public BoneInfo* Bones;
///
/// Bones base transformation (Transform[])
///
public Transform* ModelAnimPose;
public Span ModelAnimPoseAsSpan()
{
return new Span(ModelAnimPose, BoneCount);
}
public Span BonesAsSpan()
{
return new Span(Bones, BoneCount);
}
}
// Note:
// Anim pose, an array of Transform[]
// typedef Transform *ModelAnimPose; It's just an pointer array.
///
/// Model type
///
[StructLayout(LayoutKind.Sequential)]
public unsafe struct Model
{
///
/// Local transform matrix
///
public Matrix4x4 Transform;
///
/// Number of meshes
///
public int MeshCount;
///
/// Number of materials
///
public int MaterialCount;
///
/// Meshes array (Mesh *)
///
public Mesh* Meshes;
///
/// Materials array (Material *)
///
public Material* Materials;
///
/// Mesh material number (int *)
///
public int* MeshMaterial;
///
/// Skeleton for animation
///
ModelSkeleton Skeleton;
///
/// Current animation pose (Transform[])
///
public Transform* CurrentPose;
///
/// Bones animated transformation matrices
///
public Matrix4x4* BoneMatrices;
public Span BoneMatricesAsSpan()
{
return new Span(BoneMatrices, Skeleton.BoneCount);
}
public Span CurrentPoseAsSpan()
{
return new Span(CurrentPose, Skeleton.BoneCount);
}
public Span MeshMaterialAsSpan()
{
return new Span(MeshMaterial, MeshCount);
}
public Span MeshesAsSpan()
{
return new Span(Meshes, MeshCount);
}
}
///
/// ModelAnimation, contains a full animation sequence
///
[StructLayout(LayoutKind.Sequential)]
public unsafe struct ModelAnimation
{
///
/// Animation name (char[32])
///
public fixed sbyte Name[32];
///
/// Number of bones
///
public readonly int BoneCount;
///
/// Number of animation frames
///
public readonly int KeyFrameCount;
///
/// Animation sequence keyframe poses [keyframe][pose]
///
public Transform* KeyframePoses;
public Span KeyFramePosesAsSpan()
{
return new Span(KeyframePoses, KeyFrameCount);
}
public string NameToString()
{
fixed (sbyte* name = Name)
{
return Utf8StringUtils.GetUTF8String(name);
}
}
}