//
// 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 for a skinned animation
///
///
/// C++:
/// Jolt/Skeleton/SkeletalAnimation.h:18
///
/// class SkeletalAnimation : public RefTarget<SkeletalAnimation>
///
///
[InteropHandle]
public readonly partial struct SkeletalAnimation : IDisposable
{
///
///
/// Contains the current state of a joint, a local space transformation relative to its parent joint
///
///
/// C++:
/// Jolt/Skeleton/SkeletalAnimation.h:24
///
/// class JointState
///
///
[StructLayout(LayoutKind.Explicit, Size = 32)]
public partial struct JointState
{
///
///
/// Local space rotation of the joint
///
///
/// C++:
/// Jolt/Skeleton/SkeletalAnimation.h:35
///
/// Quat mRotation = Quat::sIdentity()
///
///
[FieldOffset(0)]
public floatQuat Rotation;
///
///
/// Local space translation of the joint
///
///
/// C++:
/// Jolt/Skeleton/SkeletalAnimation.h:36
///
/// Vec3 mTranslation = Vec3::sZero()
///
///
[FieldOffset(16)]
public float3 Translation;
}
public static SkeletalAnimation Create() => Jolt.PInvoke.SkeletalAnimation_Create();
///
///
/// Get the length (in seconds) of this animation
///
///
/// C++:
/// Jolt/Skeleton/SkeletalAnimation.h:63
///
/// float GetDuration() const
///
///
public float GetDuration() => Jolt.PInvoke.SkeletalAnimation_GetDuration(this);
///
///
/// Scale the size of all joints by inScale
///
///
/// C++:
/// Jolt/Skeleton/SkeletalAnimation.h:66
///
/// void ScaleJoints(float inScale)
///
///
public void ScaleJoints(float scale) => Jolt.PInvoke.SkeletalAnimation_ScaleJoints(this, scale);
///
///
/// If the animation is looping or not. If an animation is looping, the animation will continue playing
/// after completion
///
///
/// C++:
/// Jolt/Skeleton/SkeletalAnimation.h:69
///
/// void SetIsLooping(bool inIsLooping)
///
///
public void SetIsLooping(bool isLooping) => Jolt.PInvoke.SkeletalAnimation_SetIsLooping(this, isLooping);
///
///
/// C++:
/// Jolt/Skeleton/SkeletalAnimation.h:70
///
/// bool IsLooping() const
///
///
public bool IsLooping() => Jolt.PInvoke.SkeletalAnimation_IsLooping(this);
///
///
/// Get the (interpolated) joint transforms at time inTime
///
///
/// C++:
/// Jolt/Skeleton/SkeletalAnimation.h:73
///
/// void Sample(float inTime, SkeletonPose &ioPose) const
///
///
public void Sample(float time, SkeletonPose pose) => Jolt.PInvoke.SkeletalAnimation_Sample(this, time, pose);
///
///
/// Saves the state of this animation in binary form to inStream.
///
///
/// C++:
/// Jolt/Skeleton/SkeletalAnimation.h:80
///
/// void SaveBinaryState(StreamOut &inStream) const
///
///
public void SaveBinaryState(StreamOut stream) => Jolt.PInvoke.SkeletalAnimation_SaveBinaryState(this, stream);
///
///
/// Restore a saved ragdoll from inStream
///
///
/// C++:
/// Jolt/Skeleton/SkeletalAnimation.h:85
///
/// static AnimationResult sRestoreFromBinaryState(StreamIn &inStream)
///
///
///
///
/// Throws JoltException with Jolt's error message when the operation fails.
///
///
public static SkeletalAnimation RestoreFromBinaryState(StreamIn stream)
{
var _handle = Jolt.PInvoke.SkeletalAnimation_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 SkeletalAnimation.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.SkeletalAnimation_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 SkeletalAnimation RestoreFromObjectStream(ReadOnlySpan data)
{
fixed (byte* data_fixed = data)
{
var _handle = Jolt.PInvoke.SkeletalAnimation_RestoreFromObjectStream(data_fixed, (nuint)data.Length);
if (_handle.IsNull())
throw JoltException.FromLastError();
return _handle;
}
}
public void AddRef() => Jolt.PInvoke.SkeletalAnimation_AddRef(this);
public void Release() => Jolt.PInvoke.SkeletalAnimation_Release(this);
public uint GetRefCount() => Jolt.PInvoke.SkeletalAnimation_GetRefCount(this);
public void Dispose()
{
if (IsNull())
return;
Release();
}
}
}