2024-03-14 20:33:44 +08:00
|
|
|
|
#region
|
|
|
|
|
|
|
|
|
|
using System;
|
2023-09-24 13:37:10 +08:00
|
|
|
|
using nadena.dev.modular_avatar.animation;
|
2024-03-14 20:33:44 +08:00
|
|
|
|
using nadena.dev.modular_avatar.core.editor.plugin;
|
2023-09-20 18:24:36 +08:00
|
|
|
|
using nadena.dev.modular_avatar.editor.ErrorReporting;
|
|
|
|
|
using nadena.dev.ndmf;
|
2023-09-10 16:14:19 +08:00
|
|
|
|
using nadena.dev.ndmf.fluent;
|
2023-08-05 14:47:03 +08:00
|
|
|
|
using UnityEngine;
|
2024-03-14 20:33:44 +08:00
|
|
|
|
using Object = UnityEngine.Object;
|
|
|
|
|
|
|
|
|
|
#endregion
|
2023-08-05 14:47:03 +08:00
|
|
|
|
|
|
|
|
|
[assembly: ExportsPlugin(
|
2024-03-14 20:33:44 +08:00
|
|
|
|
typeof(PluginDefinition)
|
2023-08-05 14:47:03 +08:00
|
|
|
|
)]
|
|
|
|
|
|
|
|
|
|
namespace nadena.dev.modular_avatar.core.editor.plugin
|
|
|
|
|
{
|
2023-09-10 16:14:19 +08:00
|
|
|
|
class PluginDefinition : Plugin<PluginDefinition>
|
2023-08-05 14:47:03 +08:00
|
|
|
|
{
|
|
|
|
|
public override string QualifiedName => "nadena.dev.modular-avatar";
|
2023-09-10 16:14:19 +08:00
|
|
|
|
public override string DisplayName => "Modular Avatar";
|
2023-12-21 16:38:46 +08:00
|
|
|
|
public override Texture2D LogoTexture => LogoDisplay.LOGO_ASSET;
|
2023-09-17 17:16:27 +08:00
|
|
|
|
|
2024-03-14 20:33:44 +08:00
|
|
|
|
// 00a0e9
|
|
|
|
|
public override Color? ThemeColor => new Color(0x00 / 255f, 0xa0 / 255f, 0xe9 / 255f, 1);
|
|
|
|
|
|
2023-09-20 18:24:36 +08:00
|
|
|
|
protected override void OnUnhandledException(Exception e)
|
|
|
|
|
{
|
|
|
|
|
BuildReport.LogException(e);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-10 16:14:19 +08:00
|
|
|
|
protected override void Configure()
|
|
|
|
|
{
|
2023-09-17 17:16:27 +08:00
|
|
|
|
Sequence seq = InPhase(BuildPhase.Resolving);
|
|
|
|
|
seq.Run(ResolveObjectReferences.Instance);
|
|
|
|
|
// Protect against accidental destructive edits by cloning the input controllers ASAP
|
|
|
|
|
seq.Run("Clone animators", AnimationUtil.CloneAllControllers);
|
2023-08-05 14:47:03 +08:00
|
|
|
|
|
2023-09-17 17:16:27 +08:00
|
|
|
|
seq = InPhase(BuildPhase.Transforming);
|
2023-12-26 15:10:45 +08:00
|
|
|
|
seq.Run("Validate configuration",
|
2023-12-21 16:38:46 +08:00
|
|
|
|
context => ComponentValidation.ValidateAll(context.AvatarRootObject));
|
2023-09-10 16:14:19 +08:00
|
|
|
|
seq.WithRequiredExtension(typeof(ModularAvatarContext), _s1 =>
|
|
|
|
|
{
|
|
|
|
|
seq.Run(ClearEditorOnlyTags.Instance);
|
|
|
|
|
seq.Run(MeshSettingsPluginPass.Instance);
|
2024-06-03 08:52:08 +08:00
|
|
|
|
seq.Run(ScaleAdjusterPass.Instance).PreviewingWith(new ScaleAdjusterPreview());
|
2023-11-10 14:37:56 +08:00
|
|
|
|
#if MA_VRCSDK3_AVATARS
|
2024-08-11 09:03:50 +08:00
|
|
|
|
seq.Run(ReactiveObjectPrepass.Instance);
|
2023-09-10 16:14:19 +08:00
|
|
|
|
seq.Run(RenameParametersPluginPass.Instance);
|
2024-08-05 10:31:43 +08:00
|
|
|
|
seq.Run(ParameterAssignerPass.Instance);
|
2023-12-22 16:17:40 +08:00
|
|
|
|
seq.Run(MergeBlendTreePass.Instance);
|
2023-09-10 16:14:19 +08:00
|
|
|
|
seq.Run(MergeAnimatorPluginPass.Instance);
|
2024-02-12 13:59:39 +08:00
|
|
|
|
seq.Run(ApplyAnimatorDefaultValuesPass.Instance);
|
2023-11-10 14:37:56 +08:00
|
|
|
|
#endif
|
2023-09-30 23:09:43 +08:00
|
|
|
|
seq.WithRequiredExtension(typeof(AnimationServicesContext), _s2 =>
|
2023-09-10 16:14:19 +08:00
|
|
|
|
{
|
2024-10-20 09:58:41 +08:00
|
|
|
|
#if MA_VRCSDK3_AVATARS
|
2024-08-11 09:03:50 +08:00
|
|
|
|
seq.Run("Shape Changer", ctx => new ReactiveObjectPass(ctx).Execute())
|
|
|
|
|
.PreviewingWith(new ShapeChangerPreview(), new ObjectSwitcherPreview(), new MaterialSetterPreview());
|
2024-10-20 09:58:41 +08:00
|
|
|
|
|
2024-10-02 10:52:25 +08:00
|
|
|
|
// TODO: We currently run this above MergeArmaturePlugin, because Merge Armature might destroy
|
|
|
|
|
// game objects which contain Menu Installers. It'd probably be better however to teach Merge Armature
|
|
|
|
|
// to retain those objects? maybe?
|
|
|
|
|
seq.Run(MenuInstallPluginPass.Instance);
|
|
|
|
|
#endif
|
2024-10-20 09:58:41 +08:00
|
|
|
|
|
2023-09-10 16:14:19 +08:00
|
|
|
|
seq.Run(MergeArmaturePluginPass.Instance);
|
|
|
|
|
seq.Run(BoneProxyPluginPass.Instance);
|
2024-10-20 09:58:41 +08:00
|
|
|
|
#if MA_VRCSDK3_AVATARS
|
2023-09-10 16:14:19 +08:00
|
|
|
|
seq.Run(VisibleHeadAccessoryPluginPass.Instance);
|
2024-10-20 09:58:41 +08:00
|
|
|
|
#endif
|
2023-09-24 15:59:02 +08:00
|
|
|
|
seq.Run("World Fixed Object",
|
2023-10-15 17:44:53 +08:00
|
|
|
|
ctx => new WorldFixedObjectProcessor().Process(ctx)
|
2023-09-24 15:59:02 +08:00
|
|
|
|
);
|
2023-09-10 16:14:19 +08:00
|
|
|
|
seq.Run(ReplaceObjectPluginPass.Instance);
|
2023-11-10 14:37:56 +08:00
|
|
|
|
#if MA_VRCSDK3_AVATARS
|
2023-09-30 23:09:43 +08:00
|
|
|
|
seq.Run(BlendshapeSyncAnimationPluginPass.Instance);
|
2024-07-29 11:22:32 +08:00
|
|
|
|
seq.Run(GameObjectDelayDisablePass.Instance);
|
2024-10-20 09:58:41 +08:00
|
|
|
|
#endif
|
2024-08-17 09:52:04 +08:00
|
|
|
|
seq.Run(ConstraintConverterPass.Instance);
|
2023-09-10 16:14:19 +08:00
|
|
|
|
});
|
2023-11-10 14:37:56 +08:00
|
|
|
|
#if MA_VRCSDK3_AVATARS
|
2023-09-17 17:16:27 +08:00
|
|
|
|
seq.Run(PhysbonesBlockerPluginPass.Instance);
|
2023-09-17 21:21:04 +08:00
|
|
|
|
seq.Run("Fixup Expressions Menu", ctx =>
|
|
|
|
|
{
|
|
|
|
|
var maContext = ctx.Extension<ModularAvatarContext>().BuildContext;
|
|
|
|
|
FixupExpressionsMenuPass.FixupExpressionsMenu(maContext);
|
|
|
|
|
});
|
2024-12-02 04:30:49 +08:00
|
|
|
|
seq.Run(SyncParameterSequencePass.Instance);
|
2023-11-10 14:37:56 +08:00
|
|
|
|
#endif
|
2024-12-02 04:30:49 +08:00
|
|
|
|
seq.Run(RemoveVertexColorPass.Instance).PreviewingWith(new RemoveVertexColorPreview());
|
2024-09-01 07:54:48 +08:00
|
|
|
|
seq.Run(RebindHumanoidAvatarPass.Instance);
|
2023-09-20 18:24:36 +08:00
|
|
|
|
seq.Run("Purge ModularAvatar components", ctx =>
|
|
|
|
|
{
|
|
|
|
|
foreach (var component in ctx.AvatarRootTransform.GetComponentsInChildren<AvatarTagComponent>(true))
|
|
|
|
|
{
|
2024-03-14 20:33:44 +08:00
|
|
|
|
Object.DestroyImmediate(component);
|
2024-03-09 16:57:15 +08:00
|
|
|
|
}
|
2024-03-14 20:33:44 +08:00
|
|
|
|
foreach (var component in ctx.AvatarRootTransform.GetComponentsInChildren<MAMoveIndependently>(true))
|
2024-03-09 16:57:15 +08:00
|
|
|
|
{
|
2024-03-14 20:33:44 +08:00
|
|
|
|
Object.DestroyImmediate(component);
|
2023-09-20 18:24:36 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
2024-02-12 13:59:23 +08:00
|
|
|
|
#if MA_VRCSDK3_AVATARS
|
2023-12-26 15:10:45 +08:00
|
|
|
|
seq.Run(PruneParametersPass.Instance);
|
2024-02-12 13:59:23 +08:00
|
|
|
|
#endif
|
2023-09-10 16:14:19 +08:00
|
|
|
|
});
|
2023-09-17 17:16:27 +08:00
|
|
|
|
|
2023-09-10 16:14:19 +08:00
|
|
|
|
InPhase(BuildPhase.Optimizing)
|
|
|
|
|
.WithRequiredExtension(typeof(ModularAvatarContext),
|
|
|
|
|
s => s.Run(GCGameObjectsPluginPass.Instance));
|
|
|
|
|
}
|
2023-08-05 14:47:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This plugin runs very early in order to resolve all AvatarObjectReferences to their
|
|
|
|
|
/// referent before any other plugins perform heirarchy manipulations.
|
|
|
|
|
/// </summary>
|
2023-09-10 16:14:19 +08:00
|
|
|
|
internal class ResolveObjectReferences : Pass<ResolveObjectReferences>
|
2023-08-05 14:47:03 +08:00
|
|
|
|
{
|
2023-09-10 16:14:19 +08:00
|
|
|
|
protected override void Execute(ndmf.BuildContext context)
|
2023-08-05 14:47:03 +08:00
|
|
|
|
{
|
|
|
|
|
foreach (var obj in context.AvatarRootObject.GetComponentsInChildren<AvatarTagComponent>())
|
|
|
|
|
{
|
|
|
|
|
obj.ResolveReferences();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-10 16:14:19 +08:00
|
|
|
|
abstract class MAPass<T> : Pass<T> where T : Pass<T>, new()
|
2023-08-05 14:47:03 +08:00
|
|
|
|
{
|
|
|
|
|
protected BuildContext MAContext(ndmf.BuildContext context)
|
|
|
|
|
{
|
|
|
|
|
return context.Extension<ModularAvatarContext>().BuildContext;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-10 16:14:19 +08:00
|
|
|
|
class ClearEditorOnlyTags : MAPass<ClearEditorOnlyTags>
|
2023-08-05 14:47:03 +08:00
|
|
|
|
{
|
2023-09-10 16:14:19 +08:00
|
|
|
|
protected override void Execute(ndmf.BuildContext context)
|
2023-08-05 14:47:03 +08:00
|
|
|
|
{
|
|
|
|
|
Traverse(context.AvatarRootTransform);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Traverse(Transform obj)
|
|
|
|
|
{
|
|
|
|
|
// EditorOnly objects can be used for multiple purposes - users might want a camera rig to be available in
|
|
|
|
|
// play mode, for example. For now, we'll prune MA components from EditorOnly objects, but otherwise leave
|
|
|
|
|
// them in place when in play mode.
|
|
|
|
|
|
|
|
|
|
if (obj.CompareTag("EditorOnly"))
|
|
|
|
|
{
|
|
|
|
|
foreach (var component in obj.GetComponentsInChildren<AvatarTagComponent>(true))
|
|
|
|
|
{
|
2024-03-14 20:33:44 +08:00
|
|
|
|
Object.DestroyImmediate(component);
|
2023-08-05 14:47:03 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
foreach (Transform transform in obj)
|
|
|
|
|
{
|
|
|
|
|
Traverse(transform);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-10 16:14:19 +08:00
|
|
|
|
class MeshSettingsPluginPass : MAPass<MeshSettingsPluginPass>
|
2023-08-05 14:47:03 +08:00
|
|
|
|
{
|
2023-09-10 16:14:19 +08:00
|
|
|
|
protected override void Execute(ndmf.BuildContext context)
|
2023-08-05 14:47:03 +08:00
|
|
|
|
{
|
|
|
|
|
new MeshSettingsPass(MAContext(context)).OnPreprocessAvatar();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-10 14:37:56 +08:00
|
|
|
|
#if MA_VRCSDK3_AVATARS
|
2023-09-10 16:14:19 +08:00
|
|
|
|
class RenameParametersPluginPass : MAPass<RenameParametersPluginPass>
|
2023-08-05 14:47:03 +08:00
|
|
|
|
{
|
2023-09-10 16:14:19 +08:00
|
|
|
|
protected override void Execute(ndmf.BuildContext context)
|
2023-08-05 14:47:03 +08:00
|
|
|
|
{
|
|
|
|
|
new RenameParametersHook().OnPreprocessAvatar(context.AvatarRootObject, MAContext(context));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-10 16:14:19 +08:00
|
|
|
|
class MergeAnimatorPluginPass : MAPass<MergeAnimatorPluginPass>
|
2023-08-05 14:47:03 +08:00
|
|
|
|
{
|
2023-09-10 16:14:19 +08:00
|
|
|
|
protected override void Execute(ndmf.BuildContext context)
|
2023-08-05 14:47:03 +08:00
|
|
|
|
{
|
|
|
|
|
new MergeAnimatorProcessor().OnPreprocessAvatar(context.AvatarRootObject, MAContext(context));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-10 16:14:19 +08:00
|
|
|
|
class MenuInstallPluginPass : MAPass<MenuInstallPluginPass>
|
2023-08-05 14:47:03 +08:00
|
|
|
|
{
|
2023-09-10 16:14:19 +08:00
|
|
|
|
protected override void Execute(ndmf.BuildContext context)
|
2023-08-05 14:47:03 +08:00
|
|
|
|
{
|
|
|
|
|
new MenuInstallHook().OnPreprocessAvatar(context.AvatarRootObject, MAContext(context));
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-10 14:37:56 +08:00
|
|
|
|
#endif
|
2023-08-05 14:47:03 +08:00
|
|
|
|
|
2023-09-10 16:14:19 +08:00
|
|
|
|
class MergeArmaturePluginPass : MAPass<MergeArmaturePluginPass>
|
2023-08-05 14:47:03 +08:00
|
|
|
|
{
|
2023-09-10 16:14:19 +08:00
|
|
|
|
protected override void Execute(ndmf.BuildContext context)
|
2023-08-05 14:47:03 +08:00
|
|
|
|
{
|
|
|
|
|
new MergeArmatureHook().OnPreprocessAvatar(context, context.AvatarRootObject);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-10 16:14:19 +08:00
|
|
|
|
class BoneProxyPluginPass : MAPass<BoneProxyPluginPass>
|
2023-08-05 14:47:03 +08:00
|
|
|
|
{
|
2023-09-10 16:14:19 +08:00
|
|
|
|
protected override void Execute(ndmf.BuildContext context)
|
2023-08-05 14:47:03 +08:00
|
|
|
|
{
|
|
|
|
|
new BoneProxyProcessor().OnPreprocessAvatar(context.AvatarRootObject);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-20 09:58:41 +08:00
|
|
|
|
#if MA_VRCSDK3_AVATARS
|
2023-09-10 16:14:19 +08:00
|
|
|
|
class VisibleHeadAccessoryPluginPass : MAPass<VisibleHeadAccessoryPluginPass>
|
2023-08-05 14:47:03 +08:00
|
|
|
|
{
|
2023-09-10 16:14:19 +08:00
|
|
|
|
protected override void Execute(ndmf.BuildContext context)
|
2023-08-05 14:47:03 +08:00
|
|
|
|
{
|
2023-10-15 17:44:53 +08:00
|
|
|
|
new VisibleHeadAccessoryProcessor(MAContext(context)).Process();
|
2023-08-05 14:47:03 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-20 09:58:41 +08:00
|
|
|
|
#endif
|
2023-08-05 14:47:03 +08:00
|
|
|
|
|
2023-09-10 16:14:19 +08:00
|
|
|
|
class ReplaceObjectPluginPass : MAPass<ReplaceObjectPluginPass>
|
2023-08-05 14:47:03 +08:00
|
|
|
|
{
|
2023-09-10 16:14:19 +08:00
|
|
|
|
protected override void Execute(ndmf.BuildContext context)
|
2023-08-05 14:47:03 +08:00
|
|
|
|
{
|
|
|
|
|
new ReplaceObjectPass(context).Process();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-10 14:37:56 +08:00
|
|
|
|
#if MA_VRCSDK3_AVATARS
|
2023-09-10 16:14:19 +08:00
|
|
|
|
class BlendshapeSyncAnimationPluginPass : MAPass<BlendshapeSyncAnimationPluginPass>
|
2023-08-05 14:47:03 +08:00
|
|
|
|
{
|
2023-09-10 16:14:19 +08:00
|
|
|
|
protected override void Execute(ndmf.BuildContext context)
|
2023-08-05 14:47:03 +08:00
|
|
|
|
{
|
2023-10-15 17:44:53 +08:00
|
|
|
|
new BlendshapeSyncAnimationProcessor().OnPreprocessAvatar(MAContext(context));
|
2023-08-05 14:47:03 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-10 16:14:19 +08:00
|
|
|
|
class PhysbonesBlockerPluginPass : MAPass<PhysbonesBlockerPluginPass>
|
2023-08-05 14:47:03 +08:00
|
|
|
|
{
|
2023-09-10 16:14:19 +08:00
|
|
|
|
protected override void Execute(ndmf.BuildContext context)
|
2023-08-05 14:47:03 +08:00
|
|
|
|
{
|
|
|
|
|
PhysboneBlockerPass.Process(context.AvatarRootObject);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-10 14:37:56 +08:00
|
|
|
|
#endif
|
2023-08-05 14:47:03 +08:00
|
|
|
|
|
2024-09-01 07:54:48 +08:00
|
|
|
|
class RebindHumanoidAvatarPass : MAPass<RebindHumanoidAvatarPass>
|
|
|
|
|
{
|
|
|
|
|
protected override void Execute(ndmf.BuildContext context)
|
|
|
|
|
{
|
|
|
|
|
new RebindHumanoidAvatar(context).Process();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-10 16:14:19 +08:00
|
|
|
|
class GCGameObjectsPluginPass : MAPass<GCGameObjectsPluginPass>
|
2023-08-05 14:47:03 +08:00
|
|
|
|
{
|
2023-09-10 16:14:19 +08:00
|
|
|
|
protected override void Execute(ndmf.BuildContext context)
|
2023-08-05 14:47:03 +08:00
|
|
|
|
{
|
|
|
|
|
new GCGameObjectsPass(MAContext(context), context.AvatarRootObject).OnPreprocessAvatar();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|