Skip to content

Commit

Permalink
feat: animation API (work in progress)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdunderscore committed Oct 28, 2024
1 parent f16f99e commit 2bd73cd
Show file tree
Hide file tree
Showing 30 changed files with 1,489 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Editor/API/AnimatorServices.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions Editor/API/AnimatorServices/ECBComparator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using UnityEditor;

namespace nadena.dev.ndmf.animator
{
internal class ECBComparator : IComparer<EditorCurveBinding>, IEqualityComparer<EditorCurveBinding>
{
internal static ECBComparator Instance { get; } = new();

private ECBComparator()
{
}

public int Compare(EditorCurveBinding x, EditorCurveBinding y)
{
var pathComparison = string.Compare(x.path, y.path, StringComparison.Ordinal);
if (pathComparison != 0) return pathComparison;
var propertyNameComparison = string.Compare(x.propertyName, y.propertyName, StringComparison.Ordinal);
if (propertyNameComparison != 0) return propertyNameComparison;
var isPPtrCurveComparison = x.isPPtrCurve.CompareTo(y.isPPtrCurve);
if (isPPtrCurveComparison != 0) return isPPtrCurveComparison;
var isDiscreteCurveComparison = x.isDiscreteCurve.CompareTo(y.isDiscreteCurve);
if (isDiscreteCurveComparison != 0) return isDiscreteCurveComparison;
return x.isSerializeReferenceCurve.CompareTo(y.isSerializeReferenceCurve);
}

public bool Equals(EditorCurveBinding x, EditorCurveBinding y)
{
return x.path == y.path && x.propertyName == y.propertyName && x.isPPtrCurve == y.isPPtrCurve &&
x.isDiscreteCurve == y.isDiscreteCurve &&
x.isSerializeReferenceCurve == y.isSerializeReferenceCurve && Equals(x.type, y.type);
}

public int GetHashCode(EditorCurveBinding obj)
{
return HashCode.Combine(obj.path, obj.propertyName, obj.isPPtrCurve, obj.isDiscreteCurve,
obj.isSerializeReferenceCurve, obj.type);
}
}
}
3 changes: 3 additions & 0 deletions Editor/API/AnimatorServices/ECBComparator.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions Editor/API/AnimatorServices/ICommitable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Collections.Generic;

namespace nadena.dev.ndmf.animator
{
internal interface ICommitable<T>
{
/// <summary>
/// Allocates the destination unity object, but does not recurse back into the CommitContext.
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
T Prepare(CommitContext context);

/// <summary>
/// Fills in all fields of the destination unity object. This may recurse back into the CommitContext.
/// </summary>
/// <param name="context"></param>
void Commit(CommitContext context, T obj);
}

internal class CommitContext
{
private readonly Dictionary<object, object> _commitCache = new();

internal R CommitObject<R>(ICommitable<R> obj)
{
if (_commitCache.TryGetValue(obj, out var result)) return (R)result;

var resultObj = obj.Prepare(this);
_commitCache[obj] = resultObj;

obj.Commit(this, resultObj);

return resultObj;
}
}
}
3 changes: 3 additions & 0 deletions Editor/API/AnimatorServices/ICommitable.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions Editor/API/AnimatorServices/IPlatformAnimatorBindings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Collections.Generic;
using UnityEngine;

namespace nadena.dev.ndmf.animator
{
internal interface IPlatformAnimatorBindings
{
/// <summary>
/// If true, the motion asset should be maintained as-is without replacement or modification.
/// </summary>
/// <param name="m"></param>
/// <returns></returns>
bool IsSpecialMotion(Motion m);

/// <summary>
/// Returns any animator controllers that are referenced by platform-specific assets (e.g. VRCAvatarDescriptor).
/// The bool flag indicates whether the controller is overridden (true) or left as default (false).
/// </summary>
/// <returns></returns>
IEnumerable<(object, RuntimeAnimatorController, bool)> GetInnateControllers();

/// <summary>
/// Updates any innate controllers to reference new animator controllers.
/// </summary>
/// <param name="controllers"></param>
void CommitInnateControllers(IEnumerable<(object, RuntimeAnimatorController)> controllers);
}
}
3 changes: 3 additions & 0 deletions Editor/API/AnimatorServices/IPlatformAnimatorBindings.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions Editor/API/AnimatorServices/VirtualAnimatorController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using UnityEditor.Animations;

namespace nadena.dev.ndmf.animator
{
/// <summary>
/// Represents an animator controller that has been indexed by NDMF for faster manipulation. This class also
/// guarantees that certain assets have been cloned, specifically:
/// - AnimatorController
/// - StateMachine
/// - AnimatorState
/// - AnimatorStateTransition
/// - BlendTree
/// - AnimationClip
/// - Any state behaviors attached to the animator controller
/// </summary>
public class VirtualAnimatorController
{
private BuildContext _context;
private AnimatorController _controller;
}
}
3 changes: 3 additions & 0 deletions Editor/API/AnimatorServices/VirtualAnimatorController.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2bd73cd

Please sign in to comment.