//
// 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
{
///
///
/// Class that is able to map a low detail (ragdoll) skeleton to a high detail (animation) skeleton and vice
/// versa
///
///
/// C++:
/// Jolt/Skeleton/SkeletonMapper.h:13
///
/// class SkeletonMapper : public RefTarget<SkeletonMapper>
///
///
[InteropHandle]
public readonly partial struct SkeletonMapper : IDisposable
{
///
///
/// A joint that maps 1-on-1 to a joint in the other skeleton
///
///
/// C++:
/// Jolt/Skeleton/SkeletonMapper.h:17
///
/// class Mapping
///
///
[StructLayout(LayoutKind.Explicit, Size = 144)]
public partial struct Mapping
{
///
///
/// Index of joint from skeleton 1
///
///
/// C++:
/// Jolt/Skeleton/SkeletonMapper.h:27
///
/// int mJointIdx1
///
///
[FieldOffset(0)]
public int JointIdx1;
///
///
/// Corresponding index of joint from skeleton 2
///
///
/// C++:
/// Jolt/Skeleton/SkeletonMapper.h:28
///
/// int mJointIdx2
///
///
[FieldOffset(4)]
public int JointIdx2;
///
///
/// Transforms this joint from skeleton 1 to 2
///
///
/// C++:
/// Jolt/Skeleton/SkeletonMapper.h:29
///
/// Mat44 mJoint1To2
///
///
[FieldOffset(16)]
public float4x4 Joint1To2;
///
///
/// Inverse of the transform above
///
///
/// C++:
/// Jolt/Skeleton/SkeletonMapper.h:30
///
/// Mat44 mJoint2To1
///
///
[FieldOffset(80)]
public float4x4 Joint2To1;
}
///
///
/// Joints that could not be mapped from skeleton 1 to 2
///
///
/// C++:
/// Jolt/Skeleton/SkeletonMapper.h:45
///
/// class Unmapped
///
///
[StructLayout(LayoutKind.Explicit, Size = 8)]
public partial struct Unmapped
{
///
///
/// Joint index of unmappable joint
///
///
/// C++:
/// Jolt/Skeleton/SkeletonMapper.h:51
///
/// int mJointIdx
///
///
[FieldOffset(0)]
public int JointIdx;
///
///
/// Parent joint index of unmappable joint
///
///
/// C++:
/// Jolt/Skeleton/SkeletonMapper.h:52
///
/// int mParentJointIdx
///
///
[FieldOffset(4)]
public int ParentJointIdx;
}
///
///
/// Joints that should have their translation locked (fixed)
///
///
/// C++:
/// Jolt/Skeleton/SkeletonMapper.h:56
///
/// class Locked
///
///
[StructLayout(LayoutKind.Explicit, Size = 32)]
public partial struct Locked
{
///
///
/// Joint index of joint with locked translation (in skeleton 2)
///
///
/// C++:
/// Jolt/Skeleton/SkeletonMapper.h:59
///
/// int mJointIdx
///
///
[FieldOffset(0)]
public int JointIdx;
///
///
/// Parent joint index of joint with locked translation (in skeleton 2)
///
///
/// C++:
/// Jolt/Skeleton/SkeletonMapper.h:60
///
/// int mParentJointIdx
///
///
[FieldOffset(4)]
public int ParentJointIdx;
///
///
/// Translation of neutral pose
///
///
/// C++:
/// Jolt/Skeleton/SkeletonMapper.h:61
///
/// Vec3 mTranslation
///
///
[FieldOffset(16)]
public float3 Translation;
}
public static SkeletonMapper Create() => Jolt.PInvoke.SkeletonMapper_Create();
///
///
/// Default function that checks if the names of the joints are equal
///
///
/// C++:
/// Jolt/Skeleton/SkeletonMapper.h:68
///
/// static bool sDefaultCanMapJoint(const Skeleton *inSkeleton1, int inIndex1, const Skeleton *inSkeleton2, int inIndex2)
///
///
public static bool DefaultCanMapJoint(Skeleton skeleton1, int index1, Skeleton skeleton2, int index2) =>
Jolt.PInvoke.SkeletonMapper_DefaultCanMapJoint(skeleton1, index1, skeleton2, index2);
///
///
/// Initialize the skeleton mapper. Skeleton 1 should be the (low detail) ragdoll skeleton and skeleton 2
/// the (high detail) animation skeleton. We assume that each joint in skeleton 1 can be mapped to a joint
/// in skeleton 2 (if not mapping from animation skeleton to ragdoll skeleton will be undefined). Skeleton 2
/// should have the same hierarchy as skeleton 1 but can contain extra joints between those in skeleton 1
/// and it can have extra joints at the root and leaves of the skeleton.
///
///
/// C++:
/// Jolt/Skeleton/SkeletonMapper.h:81
///
/// void Initialize(const Skeleton *inSkeleton1, const Mat44 *inNeutralPose1, const Skeleton *inSkeleton2, const Mat44 *inNeutralPose2, const CanMapJoint &inCanMapJoint = sDefaultCanMapJoint)
///
///
///
///
/// Initialize the skeleton mapper. Skeleton 1 should be the (low detail) ragdoll skeleton and skeleton 2 the (high detail) animation skeleton.
/// We assume that each joint in skeleton 1 can be mapped to a joint in skeleton 2 (if not mapping from animation skeleton to ragdoll skeleton will be undefined).
/// Skeleton 2 should have the same hierarchy as skeleton 1 but can contain extra joints between those in skeleton 1 and it can have extra joints at the root and leaves of the skeleton.
/// @param inSkeleton1 Source skeleton to map from.
/// @param inNeutralPose1 Neutral pose of the source skeleton (model space)
/// @param inSkeleton2 Target skeleton to map to.
/// @param inNeutralPose2 Neutral pose of the target skeleton (model space), inNeutralPose1 and inNeutralPose2 must match as closely as possible, preferably the position of the mappable joints should be identical.
/// @param inCanMapJoint Function that checks if joints in skeleton 1 and skeleton 2 are equal.
///
///
/// neutralPose1 must hold exactly one element per joint in skeleton 1 - the native count is read from the
/// object itself and a span that doesn't match it throws ArgumentOutOfRangeException. The span is only used
/// for the duration of the call. A null skeleton1 throws ArgumentNullException. Throws ArgumentException
/// for skeleton1: "skeleton1 has a joint whose parent index isn't an earlier joint - parents must come
/// first, as Jolt requires."
///
///
/// neutralPose2 must hold exactly one element per joint in skeleton 2 - the native count is read from the
/// object itself and a span that doesn't match it throws ArgumentOutOfRangeException. The span is only used
/// for the duration of the call. A null skeleton2 throws ArgumentNullException. Throws ArgumentException
/// for skeleton2: "skeleton2 has a joint whose parent index isn't an earlier joint - parents must come
/// first, as Jolt requires."
///
///
/// canMapJoint: The callback is invoked from native code: it must be a static method marked
/// [UnmanagedCallersOnly(CallConvs = [typeof(CallConvCdecl)])], and userData is passed back to it verbatim.
/// Pass null for Jolt's default (SkeletonMapper::sDefaultCanMapJoint). The callback and userData are used
/// only for the duration of this call; userData may be freed when it returns.
///
///
public unsafe void Initialize(
Skeleton skeleton1,
ReadOnlySpan neutralPose1,
Skeleton skeleton2,
ReadOnlySpan neutralPose2,
delegate* unmanaged[Cdecl] canMapJoint,
nint canMapJointUserData
)
{
fixed (float4x4* neutralPose2_fixed = neutralPose2)
fixed (float4x4* neutralPose1_fixed = neutralPose1)
{
Jolt.PInvoke.SkeletonMapper_Initialize(
this,
skeleton1,
neutralPose1_fixed,
(uint)neutralPose1.Length,
skeleton2,
neutralPose2_fixed,
(uint)neutralPose2.Length,
canMapJoint,
canMapJointUserData,
out var _bufferCheck
);
if (_bufferCheck == 1)
throw new ArgumentNullException(nameof(skeleton1), "The skeleton handle is null.");
if (_bufferCheck == 2)
throw new ArgumentException(
"skeleton1 has a joint whose parent index isn't an earlier joint - parents must come first, as Jolt requires.",
nameof(skeleton1)
);
if (_bufferCheck == 3)
throw new ArgumentNullException(nameof(skeleton2), "The skeleton handle is null.");
if (_bufferCheck == 4)
throw new ArgumentException(
"skeleton2 has a joint whose parent index isn't an earlier joint - parents must come first, as Jolt requires.",
nameof(skeleton2)
);
if (_bufferCheck == 5)
throw new ArgumentOutOfRangeException(
nameof(neutralPose1),
neutralPose1.Length,
"Expected one element per joint in skeleton 1."
);
if (_bufferCheck == 6)
throw new ArgumentOutOfRangeException(
nameof(neutralPose2),
neutralPose2.Length,
"Expected one element per joint in skeleton 2."
);
}
}
///
///
/// This can be called so lock the translation of a specified set of joints in skeleton 2. Because
/// constraints are never 100% rigid, there's always a little bit of stretch in the ragdoll when the ragdoll
/// is under stress. Locking the translations of the pose will remove the visual stretch from the ragdoll
/// but will introduce a difference between the physical simulation and the visual representation.
///
///
/// C++:
/// Jolt/Skeleton/SkeletonMapper.h:90
///
/// void LockTranslations(const Skeleton *inSkeleton2, const bool *inLockedTranslations, const Mat44 *inNeutralPose2)
///
///
///
///
/// This can be called so lock the translation of a specified set of joints in skeleton 2.
/// Because constraints are never 100% rigid, there's always a little bit of stretch in the ragdoll when the ragdoll is under stress.
/// Locking the translations of the pose will remove the visual stretch from the ragdoll but will introduce a difference between the
/// physical simulation and the visual representation.
/// @param inSkeleton2 Target skeleton to map to.
/// @param inLockedTranslations An array of bools the size of inSkeleton2->GetJointCount(), for each joint indicating if the joint is locked.
/// @param inNeutralPose2 Neutral pose to take reference translations from
///
///
/// lockedTranslations must hold exactly one element per joint in skeleton 2 - the native count is read from
/// the object itself and a span that doesn't match it throws ArgumentOutOfRangeException. The span is only
/// used for the duration of the call. A null skeleton2 throws ArgumentNullException. Throws
/// ArgumentException for skeleton2: "skeleton2 has a joint whose parent index isn't an earlier joint -
/// parents must come first, as Jolt requires." Throws ArgumentException for lockedTranslations: "A root
/// joint (one with no parent) can't have its translation locked - it positions the whole skeleton."
///
///
/// neutralPose2 must hold exactly one element per joint in skeleton 2 - the native count is read from the
/// object itself and a span that doesn't match it throws ArgumentOutOfRangeException. The span is only used
/// for the duration of the call. A null skeleton2 throws ArgumentNullException.
///
///
public unsafe void LockTranslations(
Skeleton skeleton2,
ReadOnlySpan lockedTranslations,
ReadOnlySpan neutralPose2
)
{
fixed (float4x4* neutralPose2_fixed = neutralPose2)
fixed (bool* lockedTranslations_fixed = lockedTranslations)
{
Jolt.PInvoke.SkeletonMapper_LockTranslations(
this,
skeleton2,
lockedTranslations_fixed,
(uint)lockedTranslations.Length,
neutralPose2_fixed,
(uint)neutralPose2.Length,
out var _bufferCheck
);
if (_bufferCheck == 1)
throw new ArgumentNullException(nameof(skeleton2), "The skeleton handle is null.");
if (_bufferCheck == 2)
throw new ArgumentException(
"skeleton2 has a joint whose parent index isn't an earlier joint - parents must come first, as Jolt requires.",
nameof(skeleton2)
);
if (_bufferCheck == 3)
throw new ArgumentException(
"A root joint (one with no parent) can't have its translation locked - it positions the whole skeleton.",
nameof(lockedTranslations)
);
if (_bufferCheck == 4)
throw new ArgumentOutOfRangeException(
nameof(lockedTranslations),
lockedTranslations.Length,
"Expected one element per joint in skeleton 2."
);
if (_bufferCheck == 5)
throw new ArgumentOutOfRangeException(
nameof(neutralPose2),
neutralPose2.Length,
"Expected one element per joint in skeleton 2."
);
}
}
///
///
/// After Initialize(), this can be called to lock the translation of all joints in skeleton 2 below the
/// first mapped joint to those of the neutral pose. Because constraints are never 100% rigid, there's
/// always a little bit of stretch in the ragdoll when the ragdoll is under stress. Locking the translations
/// of the pose will remove the visual stretch from the ragdoll but will introduce a difference between the
/// physical simulation and the visual representation.
///
///
/// C++:
/// Jolt/Skeleton/SkeletonMapper.h:98
///
/// void LockAllTranslations(const Skeleton *inSkeleton2, const Mat44 *inNeutralPose2)
///
///
///
///
/// After Initialize(), this can be called to lock the translation of all joints in skeleton 2 below the first mapped joint to those of the neutral pose.
/// Because constraints are never 100% rigid, there's always a little bit of stretch in the ragdoll when the ragdoll is under stress.
/// Locking the translations of the pose will remove the visual stretch from the ragdoll but will introduce a difference between the
/// physical simulation and the visual representation.
/// @param inSkeleton2 Target skeleton to map to.
/// @param inNeutralPose2 Neutral pose to take reference translations from
///
///
/// neutralPose2 must hold exactly one element per joint in skeleton 2 - the native count is read from the
/// object itself and a span that doesn't match it throws ArgumentOutOfRangeException. The span is only used
/// for the duration of the call. A null skeleton2 throws ArgumentNullException. Throws ArgumentException
/// for skeleton2: "skeleton2 has a joint whose parent index isn't an earlier joint - parents must come
/// first, as Jolt requires." Throws InvalidOperationException: "The mapper has no mappings. Call Initialize
/// first." Throws ArgumentException for skeleton2: "skeleton2 is not the skeleton the mapper was
/// initialised with."
///
///
public unsafe void LockAllTranslations(Skeleton skeleton2, ReadOnlySpan neutralPose2)
{
fixed (float4x4* neutralPose2_fixed = neutralPose2)
{
Jolt.PInvoke.SkeletonMapper_LockAllTranslations(
this,
skeleton2,
neutralPose2_fixed,
(uint)neutralPose2.Length,
out var _bufferCheck
);
if (_bufferCheck == 1)
throw new ArgumentNullException(nameof(skeleton2), "The skeleton handle is null.");
if (_bufferCheck == 2)
throw new ArgumentException(
"skeleton2 has a joint whose parent index isn't an earlier joint - parents must come first, as Jolt requires.",
nameof(skeleton2)
);
if (_bufferCheck == 3)
throw new InvalidOperationException("The mapper has no mappings. Call Initialize first.");
if (_bufferCheck == 4)
throw new ArgumentException(
"skeleton2 is not the skeleton the mapper was initialised with.",
nameof(skeleton2)
);
if (_bufferCheck == 5)
throw new ArgumentOutOfRangeException(
nameof(neutralPose2),
neutralPose2.Length,
"Expected one element per joint in skeleton 2."
);
}
}
///
///
/// Map a pose. Joints that were directly mappable will be copied in model space from pose 1 to pose 2. Any
/// joints that are only present in skeleton 2 will get their model space transform calculated through the
/// local space transforms of pose 2. Joints that are part of a joint chain between two mapped joints will
/// be reoriented towards the next joint in skeleton 1. This means that it is possible for unmapped joints
/// to have some animation, but very extreme animation poses will show artifacts.
///
///
/// C++:
/// Jolt/Skeleton/SkeletonMapper.h:107
///
/// void Map(const Mat44 *inPose1ModelSpace, const Mat44 *inPose2LocalSpace, Mat44 *outPose2ModelSpace) const
///
///
///
///
/// Map a pose. Joints that were directly mappable will be copied in model space from pose 1 to pose 2. Any joints that are only present in skeleton 2
/// will get their model space transform calculated through the local space transforms of pose 2. Joints that are part of a joint chain between two
/// mapped joints will be reoriented towards the next joint in skeleton 1. This means that it is possible for unmapped joints to have some animation,
/// but very extreme animation poses will show artifacts.
/// @param inPose1ModelSpace Pose on skeleton 1 in model space
/// @param inPose2LocalSpace Pose on skeleton 2 in local space (used for the joints that cannot be mapped)
/// @param outPose2ModelSpace Model space pose on skeleton 2 (the output of the mapping)
///
///
/// pose1ModelSpace must hold at least one element per mapped joint of skeleton 1 - the native count is read
/// from the object itself and a span that doesn't match it throws ArgumentOutOfRangeException. The span is
/// only used for the duration of the call. Throws InvalidOperationException: "The mapper holds a negative
/// joint index. Only an unmapped joint's ParentJointIdx may be -1."
///
///
/// pose2LocalSpace must hold at least one element per joint of skeleton 2 - the native count is read from
/// the object itself and a span that doesn't match it throws ArgumentOutOfRangeException. The span is only
/// used for the duration of the call.
///
///
/// pose2ModelSpace must hold at least one element per joint of skeleton 2 - the native count is read from
/// the object itself and a span that doesn't match it throws ArgumentOutOfRangeException. The span is only
/// used for the duration of the call.
///
///
public unsafe void Map(
ReadOnlySpan pose1ModelSpace,
ReadOnlySpan pose2LocalSpace,
Span pose2ModelSpace
)
{
fixed (float4x4* pose2ModelSpace_fixed = pose2ModelSpace)
fixed (float4x4* pose2LocalSpace_fixed = pose2LocalSpace)
fixed (float4x4* pose1ModelSpace_fixed = pose1ModelSpace)
{
Jolt.PInvoke.SkeletonMapper_Map(
this,
pose1ModelSpace_fixed,
(uint)pose1ModelSpace.Length,
pose2LocalSpace_fixed,
(uint)pose2LocalSpace.Length,
pose2ModelSpace_fixed,
(uint)pose2ModelSpace.Length,
out var _bufferCheck
);
if (_bufferCheck == 1)
throw new InvalidOperationException(
"The mapper holds a negative joint index. Only an unmapped joint's ParentJointIdx may be -1."
);
if (_bufferCheck == 2)
throw new ArgumentOutOfRangeException(
nameof(pose1ModelSpace),
pose1ModelSpace.Length,
"Expected at least one element per mapped joint of skeleton 1."
);
if (_bufferCheck == 3)
throw new ArgumentOutOfRangeException(
nameof(pose2LocalSpace),
pose2LocalSpace.Length,
"Expected at least one element per joint of skeleton 2."
);
if (_bufferCheck == 4)
throw new ArgumentOutOfRangeException(
nameof(pose2ModelSpace),
pose2ModelSpace.Length,
"Expected at least one element per joint of skeleton 2."
);
}
}
///
///
/// Reverse map a pose, this will only use the mappings and not the chains (it assumes that all joints in
/// skeleton 1 are mapped)
///
///
/// C++:
/// Jolt/Skeleton/SkeletonMapper.h:112
///
/// void MapReverse(const Mat44 *inPose2ModelSpace, Mat44 *outPose1ModelSpace) const
///
///
///
///
/// Reverse map a pose, this will only use the mappings and not the chains (it assumes that all joints in skeleton 1 are mapped)
/// @param inPose2ModelSpace Model space pose on skeleton 2
/// @param outPose1ModelSpace When the function returns this will contain the model space pose for skeleton 1
///
///
/// pose2ModelSpace must hold at least one element per joint of skeleton 2 - the native count is read from
/// the object itself and a span that doesn't match it throws ArgumentOutOfRangeException. The span is only
/// used for the duration of the call. Throws InvalidOperationException: "The mapper holds a negative joint
/// index. Only an unmapped joint's ParentJointIdx may be -1."
///
///
/// pose1ModelSpace must hold at least one element per mapped joint of skeleton 1 - the native count is read
/// from the object itself and a span that doesn't match it throws ArgumentOutOfRangeException. The span is
/// only used for the duration of the call.
///
///
public unsafe void MapReverse(ReadOnlySpan pose2ModelSpace, Span pose1ModelSpace)
{
fixed (float4x4* pose1ModelSpace_fixed = pose1ModelSpace)
fixed (float4x4* pose2ModelSpace_fixed = pose2ModelSpace)
{
Jolt.PInvoke.SkeletonMapper_MapReverse(
this,
pose2ModelSpace_fixed,
(uint)pose2ModelSpace.Length,
pose1ModelSpace_fixed,
(uint)pose1ModelSpace.Length,
out var _bufferCheck
);
if (_bufferCheck == 1)
throw new InvalidOperationException(
"The mapper holds a negative joint index. Only an unmapped joint's ParentJointIdx may be -1."
);
if (_bufferCheck == 2)
throw new ArgumentOutOfRangeException(
nameof(pose2ModelSpace),
pose2ModelSpace.Length,
"Expected at least one element per joint of skeleton 2."
);
if (_bufferCheck == 3)
throw new ArgumentOutOfRangeException(
nameof(pose1ModelSpace),
pose1ModelSpace.Length,
"Expected at least one element per mapped joint of skeleton 1."
);
}
}
///
///
/// Search through the directly mapped joints (mMappings) and find inJoint1Idx, returns the corresponding
/// Joint2Idx or -1 if not found.
///
///
/// C++:
/// Jolt/Skeleton/SkeletonMapper.h:115
///
/// int GetMappedJointIdx(int inJoint1Idx) const
///
///
public int GetMappedJointIdx(int joint1Idx) => Jolt.PInvoke.SkeletonMapper_GetMappedJointIdx(this, joint1Idx);
///
///
/// Search through the locked translations (mLockedTranslations) and find if joint inJoint2Idx is locked.
///
///
/// C++:
/// Jolt/Skeleton/SkeletonMapper.h:118
///
/// bool IsJointTranslationLocked(int inJoint2Idx) const
///
///
public bool IsJointTranslationLocked(int joint2Idx) =>
Jolt.PInvoke.SkeletonMapper_IsJointTranslationLocked(this, joint2Idx);
///
///
/// C++:
/// Jolt/Skeleton/SkeletonMapper.h:128
///
/// MappingVector & GetMappings()
///
///
///
///
/// The span is a view of the container's own storage, not a copy, so it costs nothing to take. It's only
/// valid until that container is resized or its owner is destroyed.
///
///
[return: Brutal.Attributes.Fixed]
public unsafe ReadOnlySpan GetMappings()
{
Jolt.PInvoke.SkeletonMapper_GetMappings(this, out var _outResult);
return new ReadOnlySpan((void*)_outResult.Data, checked((int)_outResult.Count));
}
///
///
/// C++:
/// Jolt/Skeleton/SkeletonMapper.h:132
///
/// UnmappedVector & GetUnmapped()
///
///
///
///
/// The span is a view of the container's own storage, not a copy: edits land in the object that owns it.
/// It's only valid until that container is resized or its owner is destroyed.
///
///
[return: Brutal.Attributes.Fixed]
public unsafe Span GetUnmapped()
{
Jolt.PInvoke.SkeletonMapper_GetUnmapped(this, out var _outResult);
return new Span((void*)_outResult.Data, checked((int)_outResult.Count));
}
///
///
/// C++:
/// Jolt/Skeleton/SkeletonMapper.h:134
///
/// LockedVector & GetLockedTranslations()
///
///
///
///
/// The span is a view of the container's own storage, not a copy, so it costs nothing to take. It's only
/// valid until that container is resized or its owner is destroyed.
///
///
[return: Brutal.Attributes.Fixed]
public unsafe ReadOnlySpan GetLockedTranslations()
{
Jolt.PInvoke.SkeletonMapper_GetLockedTranslations(this, out var _outResult);
return new ReadOnlySpan((void*)_outResult.Data, checked((int)_outResult.Count));
}
public void AddRef() => Jolt.PInvoke.SkeletonMapper_AddRef(this);
public void Release() => Jolt.PInvoke.SkeletonMapper_Release(this);
public uint GetRefCount() => Jolt.PInvoke.SkeletonMapper_GetRefCount(this);
public void Dispose()
{
if (IsNull())
return;
Release();
}
}
}