Files
sbox-public/engine/Sandbox.Engine/Systems/SceneSystem/SceneModel.Bones.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

51 lines
1.3 KiB
C#

namespace Sandbox;
/// <summary>
/// A model scene object that supports animations and can be rendered within a <see cref="SceneWorld"/>.
/// </summary>
public sealed partial class SceneModel : SceneObject
{
public void SetBoneOverride( int boneIndex, in Transform transform )
{
if ( boneIndex < 0 ) return;
animNative.SetPhysicsBone( (ushort)boneIndex, transform );
}
public void ClearBoneOverrides()
{
animNative.ClearPhysicsBones();
}
internal 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)
/// </summary>
internal void GetBoneVelocity( int boneIndex, out Vector3 linear, out Vector3 angular )
{
linear = default;
angular = default;
if ( animNative.IsNull )
return;
var delta = animNative.m_flDeltaTime;
if ( delta <= 0.0f )
return;
var boneNow = animNative.GetWorldSpaceRenderBoneTransform( boneIndex );
var boneThen = animNative.GetWorldSpaceRenderBonePreviousTransform( boneIndex );
linear = (boneNow.Position - boneThen.Position) / delta;
var diff = Rotation.Difference( boneThen.Rotation, boneNow.Rotation );
angular = new Vector3( diff.x, diff.y, diff.z ) / delta;
}
}