SceneModel changes (#3559)

* Expose GetBoneVelocity
* Document SceneModel.Bones, expose HasBoneOverrides
* Fix spelling
* GetBoneVelocity( int ), fix GetBoneVelocities assert

---------

Co-authored-by: yuberee <59583743+yuberee@users.noreply.github.com>
This commit is contained in:
sboxbot
2025-12-07 10:26:48 +00:00
committed by GitHub
parent 4bcacf00f2
commit ac7f12719b
2 changed files with 30 additions and 6 deletions

View File

@@ -196,11 +196,11 @@ public sealed partial class SkinnedModelRenderer
public record struct BoneVelocity( Vector3 Linear, Vector3 Angular );
/// <summary>
/// Allocate an array of bone veloicities in world space
/// Allocate an array of bone velocities in world space
/// </summary>
public BoneVelocity[] GetBoneVelocities()
{
Assert.NotNull( Model, "Model should not be null when calling GetBoneTransforms" );
Assert.NotNull( Model, "Model should not be null when calling GetBoneVelocities" );
BoneVelocity[] transforms = new BoneVelocity[Model.BoneCount];
@@ -215,4 +215,18 @@ public sealed partial class SkinnedModelRenderer
return transforms;
}
/// <summary>
/// Retrieve the bone's velocities based on previous and current position
/// </summary>
public BoneVelocity GetBoneVelocity( int boneIndex )
{
Assert.NotNull( Model, "Model should not be null when calling GetBoneVelocity" );
if ( !SceneModel.IsValid() || boneIndex < 0 || boneIndex >= Model.BoneCount )
return default;
SceneModel.GetBoneVelocity( boneIndex, out var linear, out var angular );
return new BoneVelocity( linear, angular );
}
}

View File

@@ -6,6 +6,11 @@ namespace Sandbox;
/// </summary>
public sealed partial class SceneModel : SceneObject
{
/// <summary>
/// Manually override the final bone transform.
/// </summary>
/// <param name="boneIndex"></param>
/// <param name="transform">Local coordinates based on the SceneModel's transform</param>
public void SetBoneOverride( int boneIndex, in Transform transform )
{
if ( boneIndex < 0 ) return;
@@ -13,21 +18,26 @@ public sealed partial class SceneModel : SceneObject
animNative.SetPhysicsBone( (ushort)boneIndex, transform );
}
/// <summary>
/// Clears all bone transform overrides.
/// </summary>
public void ClearBoneOverrides()
{
animNative.ClearPhysicsBones();
}
internal bool HasBoneOverrides()
/// <summary>
/// Whether any bone transforms have been overridden.
/// </summary>
public bool HasBoneOverrides()
{
return animNative.HasPhysicsBones();
}
/// <summary>
/// Calculate velocity from previous and current bone transform
/// (I want to expose this public but want to make sure the math is correct first)
/// Calculates the velocity from the previous and current bone transforms.
/// </summary>
internal void GetBoneVelocity( int boneIndex, out Vector3 linear, out Vector3 angular )
public void GetBoneVelocity( int boneIndex, out Vector3 linear, out Vector3 angular )
{
linear = default;
angular = default;