mirror of
https://github.com/raylib-cs/raylib-cs
synced 2025-09-09 03:01:41 -04:00
Implement safe ModelAnimation
This commit is contained in:
@@ -6,6 +6,7 @@ using System.Security;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Unicode;
|
using System.Text.Unicode;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
using Microsoft.Toolkit.HighPerformance;
|
||||||
|
|
||||||
namespace Raylib_cs
|
namespace Raylib_cs
|
||||||
{
|
{
|
||||||
@@ -2001,7 +2002,25 @@ namespace Raylib_cs
|
|||||||
|
|
||||||
/// <summary>Load model animations from file</summary>
|
/// <summary>Load model animations from file</summary>
|
||||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
public static extern ModelAnimation* LoadModelAnimations(string fileName, ref int animsCount);
|
public static extern ModelAnimation* LoadModelAnimations(byte* fileName, int* animsCount);
|
||||||
|
|
||||||
|
public static ReadOnlySpan<ModelAnimation> LoadModelAnimations(Utf8String fileName, ref int animsCount)
|
||||||
|
{
|
||||||
|
fixed (byte* p1 = fileName)
|
||||||
|
{
|
||||||
|
fixed (int* p2 = &animsCount)
|
||||||
|
{
|
||||||
|
var model = LoadModelAnimations(p1, p2);
|
||||||
|
|
||||||
|
if ((IntPtr)model == IntPtr.Zero)
|
||||||
|
{
|
||||||
|
throw new ApplicationException("Failed to load animation");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ReadOnlySpan<ModelAnimation>(model, animsCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>Update model animation pose</summary>
|
/// <summary>Update model animation pose</summary>
|
||||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using Microsoft.Toolkit.HighPerformance;
|
||||||
|
|
||||||
namespace Raylib_cs
|
namespace Raylib_cs
|
||||||
{
|
{
|
||||||
@@ -77,26 +79,32 @@ namespace Raylib_cs
|
|||||||
/// Model animation
|
/// Model animation
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public unsafe struct ModelAnimation
|
public readonly unsafe struct ModelAnimation
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Number of bones
|
/// Number of bones
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int boneCount;
|
public readonly int boneCount;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Number of animation frames
|
/// Number of animation frames
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int frameCount;
|
public readonly int frameCount;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Bones information (skeleton, BoneInfo *)
|
/// Bones information (skeleton, BoneInfo *)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public BoneInfo *bones;
|
public readonly BoneInfo* bones;
|
||||||
|
|
||||||
|
/// <inheritdoc cref="bones"/>
|
||||||
|
public ReadOnlySpan<BoneInfo> BoneInfo => new(bones, boneCount);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Poses array by frame (Transform **)
|
/// Poses array by frame (Transform **)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Transform *framePoses;
|
public readonly Transform** framePoses;
|
||||||
|
|
||||||
|
/// <inheritdoc cref="framePoses"/>
|
||||||
|
public ReadOnlySpan2D<Transform> FramePoses => new(framePoses, frameCount,boneCount,sizeof(Transform));
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user