Skip to content

Commit

Permalink
Move animator cloning into write defaults pass
Browse files Browse the repository at this point in the history
If this was a larger project it may make sense to only do it once in the NDMF resolving phase, but otherwise this is a case of YAGNI. Cloning in the write defaults pass is fine. We can revisit this decision if more passes end up needing this. Ideally bdunderscore/ndmf#111 lands and we can migrate to that instead, since it's already duplicate work for this and Modular Avatar to both do a deep clone of avatar FX
  • Loading branch information
enitimeago committed Feb 4, 2024
1 parent 4e3ccca commit 9fd3e06
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
16 changes: 1 addition & 15 deletions Packages/enitimeago.non-destructive-mmd/Editor/MapperPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
#if NDMMD_VRCSDK3_AVATARS

using enitimeago.NonDestructiveMMD.vendor;
using System.Collections.Generic;
using System.Linq;
using nadena.dev.ndmf;
using nadena.dev.ndmf.fluent;
using UnityEditor;
using UnityEditor.Animations;
using UnityEngine;
using VRC.SDK3.Avatars.Components;

namespace enitimeago.NonDestructiveMMD
{
Expand All @@ -19,13 +11,7 @@ public class MapperPlugin : Plugin<MapperPlugin>

protected override void Configure()
{
Sequence seq = InPhase(BuildPhase.Resolving);
// Clone animator controllers first to allow safe mutation.
// Modular Avatar does this, but unless this is moved into somewhere common
// then it's not ideal to rely on it just to clone all animators.
seq.Run("Clone animators", AnimationUtil.CloneAllControllers);

seq = InPhase(BuildPhase.Transforming);
var seq = InPhase(BuildPhase.Transforming);
seq.Run(MakeBlendShapesPass.Instance);
seq.Run(WriteDefaultsPass.Instance);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#if NDMMD_VRCSDK3_AVATARS

using enitimeago.NonDestructiveMMD.vendor;
using nadena.dev.ndmf;
using UnityEditor.Animations;
using UnityEngine;
Expand All @@ -13,9 +14,16 @@ public class WriteDefaultsPass : Pass<WriteDefaultsPass>

protected override void Execute(BuildContext context)
{
// TODO: switch to NDMF solution once https://github.com/bdunderscore/ndmf/issues/111 lands
AnimationUtil.CloneAllControllers(context);
Execute(context.AvatarRootObject);
}

/// <summary>
/// Pass implementation. Assumes animator controllers are safe to mutate.
/// ThiS MUST be run after a deep clone, otherwise the avatar's underlying files WILL BE MUTATED.
/// </summary>
/// <param name="avatarRootObject"></param>
internal void Execute(GameObject avatarRootObject)
{
// TODO: need some checks but if we run checks we'll see mmd shape keys exist
Expand Down

0 comments on commit 9fd3e06

Please sign in to comment.