|
@@ -9,6 +9,9 @@ using XFORM = System.Numerics.Matrix4x4;
|
|
|
|
|
|
|
|
namespace SharpGLTF.Runtime
|
|
namespace SharpGLTF.Runtime
|
|
|
{
|
|
{
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Represents the transform states of a collection of bones.
|
|
|
|
|
+ /// </summary>
|
|
|
public class ArmatureInstance
|
|
public class ArmatureInstance
|
|
|
{
|
|
{
|
|
|
#region constructor
|
|
#region constructor
|
|
@@ -36,9 +39,13 @@ namespace SharpGLTF.Runtime
|
|
|
|
|
|
|
|
#region data
|
|
#region data
|
|
|
|
|
|
|
|
|
|
+ [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
|
|
|
private readonly IReadOnlyList<NodeTemplate> _NodeTemplates;
|
|
private readonly IReadOnlyList<NodeTemplate> _NodeTemplates;
|
|
|
|
|
+
|
|
|
|
|
+ [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
|
|
|
private readonly IReadOnlyList<NodeInstance> _NodeInstances;
|
|
private readonly IReadOnlyList<NodeInstance> _NodeInstances;
|
|
|
|
|
|
|
|
|
|
+ [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
|
|
|
private readonly IReadOnlyList<AnimationTrackInfo> _AnimationTracks;
|
|
private readonly IReadOnlyList<AnimationTrackInfo> _AnimationTracks;
|
|
|
|
|
|
|
|
#endregion
|
|
#endregion
|
|
@@ -65,39 +72,43 @@ namespace SharpGLTF.Runtime
|
|
|
#region API
|
|
#region API
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
- /// Finds the index of a named animation track.
|
|
|
|
|
|
|
+ /// Sets the matrix of a bone.
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
- /// <param name="name">The animation name</param>
|
|
|
|
|
- /// <returns>The index of the animation track, or -1 if not found.</returns>
|
|
|
|
|
- public int IndexOfTrack(string name)
|
|
|
|
|
- {
|
|
|
|
|
- for (int i = 0; i < _AnimationTracks.Count; ++i)
|
|
|
|
|
- {
|
|
|
|
|
- if (_AnimationTracks[i].Name == name) return i;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return -1;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ /// <param name="name">The name of the node to be set.</param>
|
|
|
|
|
+ /// <param name="localMatrix">A matrix relative to its parent bone.</param>
|
|
|
public void SetLocalMatrix(string name, XFORM localMatrix)
|
|
public void SetLocalMatrix(string name, XFORM localMatrix)
|
|
|
{
|
|
{
|
|
|
var n = LogicalNodes.FirstOrDefault(item => item.Name == name);
|
|
var n = LogicalNodes.FirstOrDefault(item => item.Name == name);
|
|
|
- if (n == null) return;
|
|
|
|
|
|
|
+ if (n == null) throw new ArgumentException($"{name} not found", nameof(name));
|
|
|
n.LocalMatrix = localMatrix;
|
|
n.LocalMatrix = localMatrix;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void SetModelMatrix(string name, XFORM worldMatrix)
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Sets the matrix of a bone.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="name">The name of the node to be set.</param>
|
|
|
|
|
+ /// <param name="modelMatrix">A matrix relative to the model.</param>
|
|
|
|
|
+ public void SetModelMatrix(string name, XFORM modelMatrix)
|
|
|
{
|
|
{
|
|
|
var n = LogicalNodes.FirstOrDefault(item => item.Name == name);
|
|
var n = LogicalNodes.FirstOrDefault(item => item.Name == name);
|
|
|
- if (n == null) return;
|
|
|
|
|
- n.ModelMatrix = worldMatrix;
|
|
|
|
|
|
|
+ if (n == null) throw new ArgumentException($"{name} not found", nameof(name));
|
|
|
|
|
+ n.ModelMatrix = modelMatrix;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Resets the bone transforms to their default positions.
|
|
|
|
|
+ /// </summary>
|
|
|
public void SetPoseTransforms()
|
|
public void SetPoseTransforms()
|
|
|
{
|
|
{
|
|
|
foreach (var n in _NodeInstances) n.SetPoseTransform();
|
|
foreach (var n in _NodeInstances) n.SetPoseTransform();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Sets the bone transforms from an animation frame.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="trackLogicalIndex">The animation track index.</param>
|
|
|
|
|
+ /// <param name="time">The animation time frame.</param>
|
|
|
|
|
+ /// <param name="looped">True to use the animation as a looped animation.</param>
|
|
|
public void SetAnimationFrame(int trackLogicalIndex, float time, bool looped = true)
|
|
public void SetAnimationFrame(int trackLogicalIndex, float time, bool looped = true)
|
|
|
{
|
|
{
|
|
|
if (looped)
|
|
if (looped)
|