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.Unicode;
|
||||
using System.Xml;
|
||||
using Microsoft.Toolkit.HighPerformance;
|
||||
|
||||
namespace Raylib_cs
|
||||
{
|
||||
@@ -2001,7 +2002,25 @@ namespace Raylib_cs
|
||||
|
||||
/// <summary>Load model animations from file</summary>
|
||||
[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>
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
|
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.Toolkit.HighPerformance;
|
||||
|
||||
namespace Raylib_cs
|
||||
{
|
||||
@@ -77,26 +79,32 @@ namespace Raylib_cs
|
||||
/// Model animation
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public unsafe struct ModelAnimation
|
||||
public readonly unsafe struct ModelAnimation
|
||||
{
|
||||
/// <summary>
|
||||
/// Number of bones
|
||||
/// </summary>
|
||||
public int boneCount;
|
||||
public readonly int boneCount;
|
||||
|
||||
/// <summary>
|
||||
/// Number of animation frames
|
||||
/// </summary>
|
||||
public int frameCount;
|
||||
public readonly int frameCount;
|
||||
|
||||
/// <summary>
|
||||
/// Bones information (skeleton, BoneInfo *)
|
||||
/// </summary>
|
||||
public BoneInfo *bones;
|
||||
public readonly BoneInfo* bones;
|
||||
|
||||
/// <inheritdoc cref="bones"/>
|
||||
public ReadOnlySpan<BoneInfo> BoneInfo => new(bones, boneCount);
|
||||
|
||||
/// <summary>
|
||||
/// Poses array by frame (Transform **)
|
||||
/// </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