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
|
|
@ -820,32 +820,32 @@ public static unsafe partial class Raylib
|
|||
/// <summary>Rename file (if exists)</summary>
|
||||
[LibraryImport(NativeLibName)]
|
||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||
public static partial CBool FileRename(sbyte* fileName, sbyte* fileRename);
|
||||
public static partial int FileRename(sbyte* fileName, sbyte* fileRename);
|
||||
|
||||
/// <summary>Remove file (if exists)</summary>
|
||||
[LibraryImport(NativeLibName)]
|
||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||
public static partial CBool FileRemove(sbyte* fileName);
|
||||
public static partial int FileRemove(sbyte* fileName);
|
||||
|
||||
/// <summary>Copy file from one path to another, dstPath created if it doesn't exist</summary>
|
||||
[LibraryImport(NativeLibName)]
|
||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||
public static partial CBool FileCopy(sbyte* srcPath, sbyte* dstPath);
|
||||
public static partial int FileCopy(sbyte* srcPath, sbyte* dstPath);
|
||||
|
||||
/// <summary>Move file from one path to another, dstPath created if it doesn't exist</summary>
|
||||
[LibraryImport(NativeLibName)]
|
||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||
public static partial CBool FileMove(sbyte* srcPath, sbyte* dstPath);
|
||||
public static partial int FileMove(sbyte* srcPath, sbyte* dstPath);
|
||||
|
||||
/// <summary>Replace text in an existing file</summary>
|
||||
[LibraryImport(NativeLibName)]
|
||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||
public static partial CBool FileTextReplace(sbyte* fileName, sbyte* search, sbyte* replacement);
|
||||
public static partial int FileTextReplace(sbyte* fileName, sbyte* search, sbyte* replacement);
|
||||
|
||||
/// <summary>Find text in existing file</summary>
|
||||
[LibraryImport(NativeLibName)]
|
||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||
public static partial CBool FileTextFindIndex(sbyte* fileName, sbyte* search);
|
||||
public static partial int FileTextFindIndex(sbyte* fileName, sbyte* search);
|
||||
|
||||
/// <summary>Check if file exists</summary>
|
||||
[LibraryImport(NativeLibName)]
|
||||
|
|
@ -962,7 +962,7 @@ public static unsafe partial class Raylib
|
|||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||
public static partial FilePathList GetDirectoryFileCount(sbyte* dirPath);
|
||||
|
||||
/// <summary>Get the file count in a directory</summary>
|
||||
/// <summary>Load directory filepaths with extension filtering and subdir scan; some filters available: "*.*", "FILES*", "DIRS*"</summary>
|
||||
[LibraryImport(NativeLibName)]
|
||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||
public static partial FilePathList GetDirectoryFileCountEx(sbyte* dirPath, sbyte* filter, CBool scanSubdirs);
|
||||
|
|
|
|||
|
|
@ -248,4 +248,6 @@ public unsafe struct Mesh
|
|||
public const int VboIdIndexIndices = 6;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1085,6 +1085,24 @@ public static unsafe partial class Raylib
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>Load model animations from file</summary>
|
||||
public static Span<ModelAnimation> LoadModelAnimations(string fileName)
|
||||
{
|
||||
using AnsiBuffer str1 = fileName.ToAnsiBuffer();
|
||||
int count;
|
||||
|
||||
ModelAnimation* result = LoadModelAnimations(str1.AsPointer(), &count);
|
||||
return new Span<ModelAnimation>(result, count);
|
||||
}
|
||||
|
||||
public static void UnloadModelAnimations(Span<ModelAnimation> animations)
|
||||
{
|
||||
fixed (ModelAnimation* ptr = animations)
|
||||
{
|
||||
UnloadModelAnimations(ptr, animations.Length);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Compute mesh tangents</summary>
|
||||
public static void GenMeshTangents(ref Mesh mesh)
|
||||
{
|
||||
|
|
@ -1549,6 +1567,155 @@ public static unsafe partial class Raylib
|
|||
SaveFileText(fileBuffer.AsPointer(), textBuffer.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Rename file (if exists)</summary>
|
||||
public static int FileRename(string filename, string fileRename)
|
||||
{
|
||||
|
||||
using AnsiBuffer fileBuffer = filename.ToAnsiBuffer();
|
||||
using AnsiBuffer textBuffer = fileRename.ToAnsiBuffer();
|
||||
return FileRename(fileBuffer.AsPointer(), textBuffer.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Remove file (if exists)</summary>
|
||||
public static int FileRemove(string filename)
|
||||
{
|
||||
using AnsiBuffer fileBuffer = filename.ToAnsiBuffer();
|
||||
return FileRemove(fileBuffer.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Copy file from one path to another, dstPath created if it doesn't exist</summary>
|
||||
public static int FileCopy(string srcPath, string dstPath)
|
||||
{
|
||||
using AnsiBuffer srcBuffer = srcPath.ToAnsiBuffer();
|
||||
using AnsiBuffer dstBuffer = dstPath.ToAnsiBuffer();
|
||||
return FileCopy(srcBuffer.AsPointer(), dstBuffer.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Move file from one path to another, dstPath created if it doesn't exist</summary>
|
||||
public static int FileMove(string srcPath, string dstPath)
|
||||
{
|
||||
using AnsiBuffer srcBuffer = srcPath.ToAnsiBuffer();
|
||||
using AnsiBuffer dstBuffer = dstPath.ToAnsiBuffer();
|
||||
return FileMove(srcBuffer.AsPointer(), dstBuffer.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Replace text in an existing file</summary>
|
||||
public static int FileTextReplace(string fileName, string search, string replacement)
|
||||
{
|
||||
using AnsiBuffer fileBuffer = fileName.ToAnsiBuffer();
|
||||
using AnsiBuffer searchBuffer = search.ToAnsiBuffer();
|
||||
using AnsiBuffer replaceBuffer = replacement.ToAnsiBuffer();
|
||||
return FileTextReplace(fileBuffer.AsPointer(), searchBuffer.AsPointer(), replaceBuffer.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Find text in existing file</summary>
|
||||
public static int FileTextFindIndex(string fileName, string search)
|
||||
{
|
||||
using AnsiBuffer fileBuffer = fileName.ToAnsiBuffer();
|
||||
using AnsiBuffer searchBuffer = search.ToAnsiBuffer();
|
||||
return FileTextFindIndex(fileBuffer.AsPointer(), searchBuffer.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Check if file exists</summary>
|
||||
public static CBool FileExists(string fileName)
|
||||
{
|
||||
using AnsiBuffer fileBuffer = fileName.ToAnsiBuffer();
|
||||
return FileExists(fileBuffer.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Check if a directory path exists</summary>
|
||||
public static CBool DirectoryExists(string dirPath)
|
||||
{
|
||||
using AnsiBuffer dirBuffer = dirPath.ToAnsiBuffer();
|
||||
return DirectoryExists(dirBuffer.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Get file length in bytes</summary>
|
||||
public static int GetFileLength(string fileName)
|
||||
{
|
||||
using AnsiBuffer fileBuffer = fileName.ToAnsiBuffer();
|
||||
return GetFileLength(fileBuffer.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Get string to extension for a filename string (includes dot: '.png')</summary>
|
||||
public static string GetFileExtension(string fileName)
|
||||
{
|
||||
using AnsiBuffer fileBuffer = fileName.ToAnsiBuffer();
|
||||
return new string(GetFileExtension(fileBuffer.AsPointer()));
|
||||
}
|
||||
|
||||
/// <summary>Get string to filename for a path string</summary>
|
||||
public static string GetFileName(string fileName)
|
||||
{
|
||||
using AnsiBuffer fileBuffer = fileName.ToAnsiBuffer();
|
||||
return new string(GetFileName(fileBuffer.AsPointer()));
|
||||
}
|
||||
|
||||
/// <summary>Get filename string without extension </summary>
|
||||
public static string GetFileNameWithoutExt(string fileName)
|
||||
{
|
||||
using AnsiBuffer fileBuffer = fileName.ToAnsiBuffer();
|
||||
return new string(GetFileNameWithoutExt(fileBuffer.AsPointer()));
|
||||
}
|
||||
|
||||
/// <summary>Get full path for a given fileName with path</summary>
|
||||
public static string GetDirectoryPath(string filePath)
|
||||
{
|
||||
using AnsiBuffer fileBuffer = filePath.ToAnsiBuffer();
|
||||
return new string(GetDirectoryPath(fileBuffer.AsPointer()));
|
||||
}
|
||||
|
||||
/// <summary>Get previous directory path for a given path</summary>
|
||||
public static string GetPrevDirectoryPath(string dirPath)
|
||||
{
|
||||
using AnsiBuffer dirBuffer = dirPath.ToAnsiBuffer();
|
||||
return new string(GetPrevDirectoryPath(dirBuffer.AsPointer()));
|
||||
}
|
||||
|
||||
/// <summary>Get current working directory</summary>
|
||||
public static string GetWorkingDirectoryAsString()
|
||||
{
|
||||
return new string(GetWorkingDirectory());
|
||||
}
|
||||
|
||||
/// <summary>Get the directory of the running application</summary>
|
||||
public static string GetApplicationDirectoryAsString()
|
||||
{
|
||||
return new string(GetApplicationDirectory());
|
||||
}
|
||||
|
||||
/// <summary>Change working directory, return true on success</summary>
|
||||
public static CBool ChangeDirectory(string dirPath)
|
||||
{
|
||||
using AnsiBuffer dirBuffer = dirPath.ToAnsiBuffer();
|
||||
return ChangeDirectory(dirBuffer.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Check if a given path is a file or a directory</summary>
|
||||
public static CBool IsPathFile(string path)
|
||||
{
|
||||
using AnsiBuffer pathBuffer = path.ToAnsiBuffer();
|
||||
return IsPathFile(pathBuffer.AsPointer());
|
||||
}
|
||||
|
||||
/// <summary>Load directory filepaths</summary>
|
||||
public static FilePathList LoadDirectoryFiles(string dirPath, out int count)
|
||||
{
|
||||
using AnsiBuffer dirBuffer = dirPath.ToAnsiBuffer();
|
||||
int c = 0;
|
||||
var result = LoadDirectoryFiles(dirBuffer.AsPointer(), &c);
|
||||
count = c;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>Load directory filepaths with extension filtering and subdir scan; some filters available: "*.*", "FILES*", "DIRS*"</summary>
|
||||
public static FilePathList LoadDirectoryFilesEx(string basePath, string filter, CBool scanSubDirs)
|
||||
{
|
||||
using AnsiBuffer baseBuffer = basePath.ToAnsiBuffer();
|
||||
using AnsiBuffer filterBuffer = filter.ToAnsiBuffer();
|
||||
return LoadDirectoryFilesEx(baseBuffer.AsPointer(), filterBuffer.AsPointer(), scanSubDirs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads text from a file, reads it, saves it, unloads the file, and returns the loaded text.
|
||||
/// </summary>
|
||||
|
|
@ -1569,4 +1736,5 @@ public static unsafe partial class Raylib
|
|||
center.Y = GetScreenHeight() / 2.0f;
|
||||
return center;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Raylib_cs;
|
||||
|
|
|
|||
|
|
@ -21,6 +21,11 @@ public readonly ref struct Utf8Buffer
|
|||
return (sbyte*)_data.ToPointer();
|
||||
}
|
||||
|
||||
public unsafe byte* AsBytePointer()
|
||||
{
|
||||
return (byte*)_data.ToPointer();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Marshal.ZeroFreeCoTaskMemUTF8(_data);
|
||||
|
|
|
|||
Loading…
Reference in a new issue