Added severial examples. Corrected towards the correct return type and add utilities to prevent working with pointers
This commit is contained in:
parent
2a86968da0
commit
6c94ffb0cc
21 changed files with 1252 additions and 205 deletions
|
|
@ -19,6 +19,14 @@ public unsafe struct BoneInfo
|
|||
/// Bone parent
|
||||
/// </summary>
|
||||
public int Parent;
|
||||
|
||||
public string NameToString()
|
||||
{
|
||||
fixed (sbyte* name = Name)
|
||||
{
|
||||
return Utf8StringUtils.GetUTF8String(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -41,6 +49,16 @@ public unsafe struct ModelSkeleton
|
|||
/// Bones base transformation (Transform[])
|
||||
/// </summary>
|
||||
public Transform* ModelAnimPose;
|
||||
|
||||
public Span<Transform> ModelAnimPoseAsSpan()
|
||||
{
|
||||
return new Span<Transform>(ModelAnimPose, BoneCount);
|
||||
}
|
||||
|
||||
public Span<BoneInfo> BonesAsSpan()
|
||||
{
|
||||
return new Span<BoneInfo>(Bones, BoneCount);
|
||||
}
|
||||
}
|
||||
|
||||
// Note:
|
||||
|
|
@ -84,29 +102,52 @@ public unsafe struct Model
|
|||
public int* MeshMaterial;
|
||||
|
||||
/// <summary>
|
||||
/// Number of bones
|
||||
/// Skeleton for animation
|
||||
/// </summary>
|
||||
public int BoneCount;
|
||||
ModelSkeleton Skeleton;
|
||||
|
||||
//TODO: Span
|
||||
/// <summary>
|
||||
/// Bones information (skeleton, BoneInfo *)
|
||||
/// Current animation pose (Transform[])
|
||||
/// </summary>
|
||||
public BoneInfo* Bones;
|
||||
public Transform* CurrentPose;
|
||||
|
||||
//TODO: Span
|
||||
/// <summary>
|
||||
/// Bones base transformation (pose, Transform *)
|
||||
/// Bones animated transformation matrices
|
||||
/// </summary>
|
||||
public Transform* BindPose;
|
||||
public Matrix4x4* BoneMatrices;
|
||||
|
||||
public Span<Matrix4x4> BoneMatricesAsSpan()
|
||||
{
|
||||
return new Span<Matrix4x4>(BoneMatrices, Skeleton.BoneCount);
|
||||
}
|
||||
|
||||
public Span<Transform> CurrentPoseAsSpan()
|
||||
{
|
||||
return new Span<Transform>(CurrentPose, Skeleton.BoneCount);
|
||||
}
|
||||
|
||||
public Span<int> MeshMaterialAsSpan()
|
||||
{
|
||||
return new Span<int>(MeshMaterial, MeshCount);
|
||||
}
|
||||
|
||||
public Span<Mesh> MeshesAsSpan()
|
||||
{
|
||||
return new Span<Mesh>(Meshes, MeshCount);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Model animation
|
||||
/// ModelAnimation, contains a full animation sequence
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public unsafe struct ModelAnimation
|
||||
{
|
||||
/// <summary>
|
||||
/// Animation name (char[32])
|
||||
/// </summary>
|
||||
public fixed sbyte Name[32];
|
||||
|
||||
/// <summary>
|
||||
/// Number of bones
|
||||
/// </summary>
|
||||
|
|
@ -115,61 +156,23 @@ public unsafe struct ModelAnimation
|
|||
/// <summary>
|
||||
/// Number of animation frames
|
||||
/// </summary>
|
||||
public readonly int FrameCount;
|
||||
public readonly int KeyFrameCount;
|
||||
|
||||
/// <summary>
|
||||
/// Bones information (skeleton, BoneInfo *)
|
||||
/// Animation sequence keyframe poses [keyframe][pose]
|
||||
/// </summary>
|
||||
public readonly BoneInfo* Bones;
|
||||
public Transform* KeyframePoses;
|
||||
|
||||
/// <inheritdoc cref="Bones"/>
|
||||
public readonly ReadOnlySpan<BoneInfo> BoneInfo => new ReadOnlySpan<BoneInfo>(Bones, BoneCount);
|
||||
|
||||
/// <summary>
|
||||
/// Poses array by frame (Transform **)
|
||||
/// </summary>
|
||||
public readonly Transform** FramePoses;
|
||||
|
||||
/// <summary>
|
||||
/// Animation name (char[32])
|
||||
/// </summary>
|
||||
public fixed sbyte Name[32];
|
||||
|
||||
/// <inheritdoc cref="FramePoses"/>
|
||||
public readonly FramePosesCollection FramePosesColl => new FramePosesCollection(FramePoses, FrameCount, BoneCount);
|
||||
|
||||
public readonly struct FramePosesCollection
|
||||
public Span<Transform> KeyFramePosesAsSpan()
|
||||
{
|
||||
readonly Transform** _framePoses;
|
||||
return new Span<Transform>(KeyframePoses, KeyFrameCount);
|
||||
}
|
||||
|
||||
readonly int _frameCount;
|
||||
|
||||
readonly int _boneCount;
|
||||
|
||||
public readonly FramePoses this[int index] => new FramePoses(_framePoses[index], _boneCount);
|
||||
|
||||
public readonly Transform this[int index1, int index2] => new FramePoses(_framePoses[index1], _boneCount)[index2];
|
||||
|
||||
internal FramePosesCollection(Transform** framePoses, int frameCount, int boneCount)
|
||||
public string NameToString()
|
||||
{
|
||||
fixed (sbyte* name = Name)
|
||||
{
|
||||
this._framePoses = framePoses;
|
||||
this._frameCount = frameCount;
|
||||
this._boneCount = boneCount;
|
||||
return Utf8StringUtils.GetUTF8String(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public readonly unsafe struct FramePoses
|
||||
{
|
||||
readonly Transform* _poses;
|
||||
|
||||
readonly int _count;
|
||||
|
||||
public readonly ref Transform this[int index] => ref _poses[index];
|
||||
|
||||
internal FramePoses(Transform* poses, int count)
|
||||
{
|
||||
this._poses = poses;
|
||||
this._count = count;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue