// // Generated by Brutal.Jolt.Generate; do not edit by hand. #nullable enable using System.Runtime.CompilerServices; using Brutal.Interop; using Brutal.Numerics; namespace Brutal.JoltApi { /// /// /// Resource that contains the joint hierarchy for a skeleton /// /// /// C++: /// Jolt/Skeleton/Skeleton.h:17 ///
/// class Skeleton : public RefTarget<Skeleton> ///
///
[InteropHandle] public readonly partial struct Skeleton : IDisposable { public static Skeleton Create() => Jolt.PInvoke.Skeleton_Create(); /// /// /// C++: /// Jolt/Skeleton/Skeleton.h:44 ///
/// int GetJointCount() const ///
///
public int GetJointCount() => Jolt.PInvoke.Skeleton_GetJointCount(this); /// /// /// C++: /// Jolt/Skeleton/Skeleton.h:47 ///
/// uint AddJoint(const string_view &inName, const string_view &inParentName = string_view()) ///
///
public unsafe uint AddJoint(RefString8 name, RefString8 parentName) { fixed (byte* parentName_fixed = parentName) fixed (byte* name_fixed = name) { return Jolt.PInvoke.Skeleton_AddJoint(this, name_fixed, parentName_fixed); } } /// /// /// C++: /// Jolt/Skeleton/Skeleton.h:48 ///
/// uint AddJoint(const string_view &inName, int inParentIndex) ///
///
/// /// /// Throws ArgumentException for parentIndex: "parentIndex must be -1 (no parent) or the index of a joint /// already added." /// /// public unsafe uint AddJoint(RefString8 name, int parentIndex) { fixed (byte* name_fixed = name) { var _result = Jolt.PInvoke.Skeleton_AddJoint_2(this, name_fixed, parentIndex, out var _bufferCheck); if (_bufferCheck == 1) throw new ArgumentException( "parentIndex must be -1 (no parent) or the index of a joint already added.", nameof(parentIndex) ); return _result; } } /// /// /// Find joint by name /// /// /// C++: /// Jolt/Skeleton/Skeleton.h:52 ///
/// int GetJointIndex(const string_view &inName) const ///
///
public unsafe int GetJointIndex(RefString8 name) { fixed (byte* name_fixed = name) { return Jolt.PInvoke.Skeleton_GetJointIndex(this, name_fixed); } } /// /// /// Fill in parent joint indices based on name /// /// /// C++: /// Jolt/Skeleton/Skeleton.h:55 ///
/// void CalculateParentJointIndices() ///
///
public void CalculateParentJointIndices() => Jolt.PInvoke.Skeleton_CalculateParentJointIndices(this); /// /// /// Many of the algorithms that use the Skeleton class require that parent joints are in the mJoints array /// before their children. This function returns true if this is the case, false if not. /// /// /// C++: /// Jolt/Skeleton/Skeleton.h:59 ///
/// bool AreJointsCorrectlyOrdered() const ///
///
public bool AreJointsCorrectlyOrdered() => Jolt.PInvoke.Skeleton_AreJointsCorrectlyOrdered(this); /// /// /// Saves the state of this object in binary form to inStream. /// /// /// C++: /// Jolt/Skeleton/Skeleton.h:62 ///
/// void SaveBinaryState(StreamOut &inStream) const ///
///
public void SaveBinaryState(StreamOut stream) => Jolt.PInvoke.Skeleton_SaveBinaryState(this, stream); /// /// /// Restore the state of this object from inStream. /// /// /// C++: /// Jolt/Skeleton/Skeleton.h:65 ///
/// static SkeletonResult sRestoreFromBinaryState(StreamIn &inStream) ///
///
/// /// /// Throws JoltException with Jolt's error message when the operation fails. /// /// public static Skeleton RestoreFromBinaryState(StreamIn stream) { var _handle = Jolt.PInvoke.Skeleton_RestoreFromBinaryState(stream); if (_handle.IsNull()) throw JoltException.FromLastError(); return _handle; } /// /// /// Serialises this object (and everything it references) into buffer as a Jolt object stream, and returns /// the total size of that stream. Nothing is written past the end of the buffer, so a return value larger /// than buffer.Length means the buffer was too small and the call should be retried with one that size - /// passing an empty span is how you ask for the size. Each call serialises the object's current state /// independently and retains nothing after it returns. If the object grows between the size query and the /// fill, use the fill's returned size to retry with a larger buffer. Text streams are human-readable and /// portable; binary ones are smaller. Read one back with Skeleton.RestoreFromObjectStream. Throws /// JoltException with Jolt's error message when the object can't be written, and /// ArgumentOutOfRangeException when streamType is neither Text nor Binary. /// /// public unsafe ByteSize SaveObjectStream(Span buffer, ObjectStreamType streamType = ObjectStreamType.Text) { fixed (byte* buffer_fixed = buffer) { if (streamType is not (ObjectStreamType.Text or ObjectStreamType.Binary)) throw new ArgumentOutOfRangeException( nameof(streamType), streamType, "Not an object stream format." ); var _size = Jolt.PInvoke.Skeleton_SaveObjectStream( this, buffer_fixed, (nuint)buffer.Length, streamType ); if (_size == 0) throw JoltException.FromLastError(); return (ByteSize)_size; } } /// /// /// Reads back an object stream written by SaveObjectStream (or by Jolt's own tools - the .tof and .bof /// asset files), in either the text or the binary format: the stream's header says which. The factory has /// to be up and RegisterTypes() called first, since class names are resolved through it. A stream that /// isn't an object stream, is a different version, or holds a different type throws JoltException with /// Jolt's error message. Truncation is NOT reliably caught: Jolt's reader treats running out of data as a /// normal end of stream, so a stream cut off after the main object was read comes back as an object whose /// unresolved references were silently set to null - code reading untrusted input has to validate what it /// got. The returned handle is yours - it carries its own reference, so Dispose it once when you are done /// with it. /// /// public static unsafe Skeleton RestoreFromObjectStream(ReadOnlySpan data) { fixed (byte* data_fixed = data) { var _handle = Jolt.PInvoke.Skeleton_RestoreFromObjectStream(data_fixed, (nuint)data.Length); if (_handle.IsNull()) throw JoltException.FromLastError(); return _handle; } } public void AddRef() => Jolt.PInvoke.Skeleton_AddRef(this); public void Release() => Jolt.PInvoke.Skeleton_Release(this); public uint GetRefCount() => Jolt.PInvoke.Skeleton_GetRefCount(this); public void Dispose() { if (IsNull()) return; Release(); } } }