mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-04-11 23:19:00 +08:00
Rollback ReactiveObjectPass, use another approach
This commit is contained in:
parent
708bc6562f
commit
97af2308d6
@ -26,10 +26,7 @@ namespace nadena.dev.modular_avatar.core.editor
|
|||||||
|
|
||||||
private AnimationClip _initialStateClip;
|
private AnimationClip _initialStateClip;
|
||||||
private bool _writeDefaults;
|
private bool _writeDefaults;
|
||||||
|
|
||||||
private AnimatorCombiner _combineSession;
|
|
||||||
private AnimatorController _animController;
|
|
||||||
|
|
||||||
public ReactiveObjectPass(ndmf.BuildContext context)
|
public ReactiveObjectPass(ndmf.BuildContext context)
|
||||||
{
|
{
|
||||||
this.context = context;
|
this.context = context;
|
||||||
@ -37,37 +34,26 @@ namespace nadena.dev.modular_avatar.core.editor
|
|||||||
|
|
||||||
internal void Execute()
|
internal void Execute()
|
||||||
{
|
{
|
||||||
var fxController = FindFxController();
|
|
||||||
|
|
||||||
// Having a WD OFF layer after WD ON layers can break WD. We match the behavior of the existing states,
|
// Having a WD OFF layer after WD ON layers can break WD. We match the behavior of the existing states,
|
||||||
// and if mixed, use WD ON to maximize compatibility.
|
// and if mixed, use WD ON to maximize compatibility.
|
||||||
_writeDefaults = MergeAnimatorProcessor.ProbeWriteDefaults(fxController.animatorController as AnimatorController) ?? true;
|
_writeDefaults = MergeAnimatorProcessor.ProbeWriteDefaults(FindFxController().animatorController as AnimatorController) ?? true;
|
||||||
|
|
||||||
_combineSession = new AnimatorCombiner(context, fxController.animatorController != null ? fxController.animatorController.name : "FX (Reactive Objects)");
|
|
||||||
_combineSession.AddController("", fxController.animatorController as AnimatorController, null);
|
|
||||||
_animController = new AnimatorController();
|
|
||||||
|
|
||||||
var analysis = new ReactiveObjectAnalyzer(context).Analyze(context.AvatarRootObject);
|
var analysis = new ReactiveObjectAnalyzer(context).Analyze(context.AvatarRootObject);
|
||||||
|
|
||||||
var shapes = analysis.Shapes;
|
var shapes = analysis.Shapes;
|
||||||
var initialStates = analysis.InitialStates;
|
var initialStates = analysis.InitialStates;
|
||||||
|
|
||||||
GenerateActiveSelfProxies(shapes);
|
GenerateActiveSelfProxies(shapes);
|
||||||
|
|
||||||
ProcessMeshDeletion(initialStates, shapes);
|
ProcessMeshDeletion(initialStates, shapes);
|
||||||
|
|
||||||
ProcessInitialStates(initialStates, shapes);
|
ProcessInitialStates(initialStates, shapes);
|
||||||
ProcessInitialAnimatorVariables(shapes);
|
ProcessInitialAnimatorVariables(shapes);
|
||||||
|
|
||||||
foreach (var groups in shapes.Values)
|
foreach (var groups in shapes.Values)
|
||||||
{
|
{
|
||||||
ProcessShapeKey(groups);
|
ProcessShapeKey(groups);
|
||||||
}
|
}
|
||||||
|
|
||||||
_combineSession.AddController("", _animController, null);
|
|
||||||
FinishCombineSession();
|
|
||||||
Object.DestroyImmediate(_animController); // Cleanup
|
|
||||||
_combineSession = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GenerateActiveSelfProxies(Dictionary<TargetProp, AnimatedProperty> shapes)
|
private void GenerateActiveSelfProxies(Dictionary<TargetProp, AnimatedProperty> shapes)
|
||||||
@ -576,7 +562,24 @@ namespace nadena.dev.modular_avatar.core.editor
|
|||||||
|
|
||||||
private void ApplyController(AnimatorStateMachine asm, string layerName)
|
private void ApplyController(AnimatorStateMachine asm, string layerName)
|
||||||
{
|
{
|
||||||
var paramList = _animController.parameters.ToList();
|
var fx = FindFxController();
|
||||||
|
|
||||||
|
if (fx.animatorController == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("No FX layer found");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!context.IsTemporaryAsset(fx.animatorController))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("FX layer is not a temporary asset");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(fx.animatorController is AnimatorController animController))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("FX layer is not an animator controller");
|
||||||
|
}
|
||||||
|
|
||||||
|
var paramList = animController.parameters.ToList();
|
||||||
var paramSet = paramList.Select(p => p.name).ToHashSet();
|
var paramSet = paramList.Select(p => p.name).ToHashSet();
|
||||||
|
|
||||||
foreach (var paramName in initialValues.Keys.Except(paramSet))
|
foreach (var paramName in initialValues.Keys.Except(paramSet))
|
||||||
@ -590,9 +593,9 @@ namespace nadena.dev.modular_avatar.core.editor
|
|||||||
paramSet.Add(paramName);
|
paramSet.Add(paramName);
|
||||||
}
|
}
|
||||||
|
|
||||||
_animController.parameters = paramList.ToArray();
|
animController.parameters = paramList.ToArray();
|
||||||
|
|
||||||
_animController.layers = _animController.layers.Append(
|
animController.layers = animController.layers.Append(
|
||||||
new AnimatorControllerLayer
|
new AnimatorControllerLayer
|
||||||
{
|
{
|
||||||
stateMachine = asm,
|
stateMachine = asm,
|
||||||
@ -609,29 +612,6 @@ namespace nadena.dev.modular_avatar.core.editor
|
|||||||
|
|
||||||
return fx;
|
return fx;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FinishCombineSession()
|
|
||||||
{
|
|
||||||
for (int i = 0; i < context.AvatarDescriptor.baseAnimationLayers.Length; i++)
|
|
||||||
{
|
|
||||||
if (context.AvatarDescriptor.baseAnimationLayers[i].type == VRCAvatarDescriptor.AnimLayerType.FX)
|
|
||||||
{
|
|
||||||
context.AvatarDescriptor.baseAnimationLayers[i].animatorController = _combineSession.Finish();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// When we don't have an FX layer, we create one.
|
|
||||||
context.AvatarDescriptor.baseAnimationLayers = context.AvatarDescriptor.baseAnimationLayers.Append(
|
|
||||||
new VRCAvatarDescriptor.CustomAnimLayer
|
|
||||||
{
|
|
||||||
type = VRCAvatarDescriptor.AnimLayerType.FX,
|
|
||||||
isDefault = false,
|
|
||||||
isEnabled = true,
|
|
||||||
animatorController = _combineSession.Finish(),
|
|
||||||
}
|
|
||||||
).ToArray();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using nadena.dev.ndmf;
|
using nadena.dev.ndmf;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEditor.Animations;
|
||||||
using VRC.SDK3.Avatars.ScriptableObjects;
|
using VRC.SDK3.Avatars.ScriptableObjects;
|
||||||
|
|
||||||
namespace nadena.dev.modular_avatar.core.editor
|
namespace nadena.dev.modular_avatar.core.editor
|
||||||
@ -186,6 +187,19 @@ namespace nadena.dev.modular_avatar.core.editor
|
|||||||
|
|
||||||
expParams.parameters = expParams.parameters.Concat(newParameters.Values).ToArray();
|
expParams.parameters = expParams.parameters.Concat(newParameters.Values).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_mamiByParam.Count > 0)
|
||||||
|
{
|
||||||
|
// This make sures the parameters are correctly merged into the FX layer.
|
||||||
|
context.AvatarRootObject.AddComponent<ModularAvatarMergeAnimator>().animator = new AnimatorController
|
||||||
|
{
|
||||||
|
parameters = _mamiByParam.Keys.Select(name => new AnimatorControllerParameter
|
||||||
|
{
|
||||||
|
name = name,
|
||||||
|
type = AnimatorControllerParameterType.Float,
|
||||||
|
}).ToArray(),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static ControlCondition AssignMenuItemParameter(
|
internal static ControlCondition AssignMenuItemParameter(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user