mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-01-30 10:12:59 +08:00
chore: Fix non-VRChat support (#650)
* add referenced assembly * remove unused usings * MA Merge Blend Tree is VRC specific because it expects VRC style Animator Layer setup * PruneParametersPass is VRChat specific * fix: use FindAvatarTransformInParents() to be more cross platform * fix MergeArmatureHook: nop logic for PhysBones if we do not dedup PhysBones * fix AnimatorCombiner: ignore VRC components when non-VRC btw, is AnimatorCombiner VRC specific? * conditional compile some VRChat specific tests
This commit is contained in:
parent
900c9d2a02
commit
5359e3b006
@ -22,8 +22,6 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#if MA_VRCSDK3_AVATARS
|
||||
#endif
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -34,9 +32,12 @@ using nadena.dev.ndmf.util;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Animations;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
#if MA_VRCSDK3_AVATARS
|
||||
using VRC.SDK3.Avatars.Components;
|
||||
using VRC.SDKBase;
|
||||
using Object = UnityEngine.Object;
|
||||
#endif
|
||||
|
||||
namespace nadena.dev.modular_avatar.animation
|
||||
{
|
||||
@ -64,7 +65,9 @@ namespace nadena.dev.modular_avatar.animation
|
||||
|
||||
private int _controllerBaseLayer = 0;
|
||||
|
||||
#if MA_VRCSDK3_AVATARS
|
||||
public VRC_AnimatorLayerControl.BlendableLayer? BlendableLayer;
|
||||
#endif
|
||||
|
||||
public AnimatorCombiner(ndmf.BuildContext context, String assetName)
|
||||
{
|
||||
@ -134,23 +137,27 @@ namespace nadena.dev.modular_avatar.animation
|
||||
var newBehaviors = new List<StateMachineBehaviour>();
|
||||
foreach (var b in behaviours)
|
||||
{
|
||||
if (b is VRCAnimatorLayerControl alc && alc.playable == BlendableLayer)
|
||||
switch (b)
|
||||
{
|
||||
int newLayer = -1;
|
||||
if (alc.layer >= 0 && alc.layer < layerIndexMappings.Length)
|
||||
{
|
||||
newLayer = layerIndexMappings[alc.layer];
|
||||
}
|
||||
#if MA_VRCSDK3_AVATARS
|
||||
case VRCAnimatorLayerControl alc when alc.playable == BlendableLayer:
|
||||
int newLayer = -1;
|
||||
if (alc.layer >= 0 && alc.layer < layerIndexMappings.Length)
|
||||
{
|
||||
newLayer = layerIndexMappings[alc.layer];
|
||||
}
|
||||
|
||||
if (newLayer != -1)
|
||||
{
|
||||
alc.layer = newLayer;
|
||||
newBehaviors.Add(alc);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
newBehaviors.Add(b);
|
||||
if (newLayer != -1)
|
||||
{
|
||||
alc.layer = newLayer;
|
||||
newBehaviors.Add(alc);
|
||||
}
|
||||
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
newBehaviors.Add(b);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using static nadena.dev.modular_avatar.core.editor.Localization;
|
||||
|
@ -1,4 +1,6 @@
|
||||
using UnityEditor;
|
||||
#if MA_VRCSDK3_AVATARS
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEditor.Animations;
|
||||
using static nadena.dev.modular_avatar.core.editor.Localization;
|
||||
|
||||
@ -34,4 +36,6 @@ namespace nadena.dev.modular_avatar.core.editor
|
||||
ShowLanguageUI();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -46,7 +46,9 @@ namespace nadena.dev.modular_avatar.core.editor
|
||||
|
||||
private ndmf.BuildContext frameworkContext;
|
||||
private BuildContext context;
|
||||
#if MA_VRCSDK3_AVATARS
|
||||
private Dictionary<Transform, VRCPhysBoneBase> physBoneByRootBone;
|
||||
#endif
|
||||
private BoneDatabase BoneDatabase = new BoneDatabase();
|
||||
|
||||
private PathMappings PathMappings => frameworkContext.Extension<AnimationServicesContext>()
|
||||
@ -60,9 +62,11 @@ namespace nadena.dev.modular_avatar.core.editor
|
||||
{
|
||||
this.frameworkContext = context;
|
||||
this.context = context.Extension<ModularAvatarContext>().BuildContext;
|
||||
#if MA_VRCSDK3_AVATARS
|
||||
physBoneByRootBone = new Dictionary<Transform, VRCPhysBoneBase>();
|
||||
foreach (var physbone in avatarGameObject.transform.GetComponentsInChildren<VRCPhysBoneBase>(true))
|
||||
physBoneByRootBone[physbone.GetRootTransform()] = physbone;
|
||||
#endif
|
||||
|
||||
if (avatarGameObject.TryGetComponent<Animator>(out var animator) && animator.isHuman)
|
||||
{
|
||||
@ -390,12 +394,16 @@ namespace nadena.dev.modular_avatar.core.editor
|
||||
|
||||
private bool NotAffectedByPhysBoneOrSimilarChainsAsTarget(Transform child, Transform target)
|
||||
{
|
||||
#if MA_VRCSDK3_AVATARS
|
||||
// not affected
|
||||
if (!physBoneByRootBone.TryGetValue(child, out VRCPhysBoneBase physBone)) return true;
|
||||
|
||||
var ignores = new HashSet<Transform>(physBone.ignoreTransforms.Where(x => x));
|
||||
|
||||
return IsSimilarChainInPosition(child, target, ignores);
|
||||
#else
|
||||
return IsSimilarChainInPosition(child, target, new HashSet<Transform>());
|
||||
#endif
|
||||
}
|
||||
|
||||
// Returns true if child and target are in similar position and children are recursively.
|
||||
|
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
#if MA_VRCSDK3_AVATARS
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
using nadena.dev.modular_avatar.animation;
|
||||
@ -168,4 +170,6 @@ namespace nadena.dev.modular_avatar.core.editor
|
||||
return _rootBlendTree;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,4 +1,6 @@
|
||||
using System.Linq;
|
||||
#if MA_VRCSDK3_AVATARS
|
||||
|
||||
using System.Linq;
|
||||
using nadena.dev.ndmf;
|
||||
|
||||
namespace nadena.dev.modular_avatar.core.editor
|
||||
@ -14,4 +16,6 @@ namespace nadena.dev.modular_avatar.core.editor
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -83,7 +83,9 @@ namespace nadena.dev.modular_avatar.core.editor.plugin
|
||||
UnityEngine.Object.DestroyImmediate(component);
|
||||
}
|
||||
});
|
||||
#if MA_VRCSDK3_AVATARS
|
||||
seq.Run(PruneParametersPass.Instance);
|
||||
#endif
|
||||
});
|
||||
|
||||
InPhase(BuildPhase.Optimizing)
|
||||
|
@ -15,6 +15,7 @@
|
||||
"precompiledReferences": [
|
||||
"Newtonsoft.Json.dll",
|
||||
"System.Collections.Immutable.dll",
|
||||
"System.Memory.dll",
|
||||
"VRCSDKBase.dll",
|
||||
"VRCSDKBase-Editor.dll",
|
||||
"VRCSDK3A.dll",
|
||||
|
@ -1,4 +1,6 @@
|
||||
using UnityEngine;
|
||||
#if MA_VRCSDK3_AVATARS
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace nadena.dev.modular_avatar.core
|
||||
{
|
||||
@ -11,4 +13,6 @@ namespace nadena.dev.modular_avatar.core
|
||||
public MergeAnimatorPathMode PathMode = MergeAnimatorPathMode.Relative;
|
||||
public AvatarObjectReference RelativePathRoot = new AvatarObjectReference();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -152,7 +152,7 @@ namespace nadena.dev.modular_avatar.core
|
||||
|
||||
var oldPatches = new HashSet<ScalePatch>(this.patches);
|
||||
var newPatches = new HashSet<ScalePatch>();
|
||||
var avatarRoot = RuntimeUtil.FindAvatarInParents(selfTransform);
|
||||
var avatarRoot = RuntimeUtil.FindAvatarTransformInParents(selfTransform);
|
||||
|
||||
if (avatarRoot != null)
|
||||
{
|
||||
|
@ -1,4 +1,6 @@
|
||||
using System.Collections;
|
||||
#if MA_VRCSDK3_AVATARS
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using modular_avatar_tests;
|
||||
using nadena.dev.modular_avatar.core.editor;
|
||||
@ -37,4 +39,6 @@ namespace modular_avatar_tests
|
||||
Assert.AreEqual(3, ((VRCAnimatorLayerControl)l3a.stateMachine.defaultState.behaviours[0]).layer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
#if MA_VRCSDK3_AVATARS
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using nadena.dev.modular_avatar.core;
|
||||
using nadena.dev.modular_avatar.core.editor;
|
||||
@ -125,4 +127,6 @@ namespace modular_avatar_tests
|
||||
return merge;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,4 +1,6 @@
|
||||
using System.Linq;
|
||||
#if MA_VRCSDK3_AVATARS
|
||||
|
||||
using System.Linq;
|
||||
using nadena.dev.ndmf;
|
||||
using NUnit.Framework;
|
||||
using UnityEditor.Animations;
|
||||
@ -25,4 +27,6 @@ namespace modular_avatar_tests
|
||||
}, layerNames);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -3,7 +3,6 @@ using modular_avatar_tests;
|
||||
using nadena.dev.modular_avatar.core.editor;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using VRC.SDK3.Avatars.Components;
|
||||
|
||||
public class PreferFirstHipsMatch : TestBase
|
||||
{
|
||||
@ -11,7 +10,9 @@ public class PreferFirstHipsMatch : TestBase
|
||||
public void SetupHeuristicPrefersFirstHipsMatch()
|
||||
{
|
||||
var root = CreateCommonPrefab("shapell.fbx");
|
||||
root.AddComponent<VRCAvatarDescriptor>();
|
||||
#if MA_VRCSDK3_AVATARS
|
||||
root.AddComponent<VRC.SDK3.Avatars.Components.VRCAvatarDescriptor>();
|
||||
#endif
|
||||
var root_hips = root.GetComponent<Animator>().GetBoneTransform(HumanBodyBones.Hips).gameObject;
|
||||
var root_armature = root_hips.transform.parent.gameObject;
|
||||
var root_secondary = CreateChild(root, "PBC");
|
||||
@ -26,4 +27,4 @@ public class PreferFirstHipsMatch : TestBase
|
||||
Assert.AreSame(root_hips, det_av_hips);
|
||||
Assert.AreSame(outfit_hips, det_outfit_hips);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,12 @@ using nadena.dev.modular_avatar.core.editor;
|
||||
using NUnit.Framework;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using ModularAvatarMergeArmature = nadena.dev.modular_avatar.core.ModularAvatarMergeArmature;
|
||||
|
||||
#if MA_VRCSDK3_AVATARS
|
||||
using VRC.SDK3.Avatars.Components;
|
||||
using VRC.SDK3.Dynamics.PhysBone.Components;
|
||||
using ModularAvatarMergeArmature = nadena.dev.modular_avatar.core.ModularAvatarMergeArmature;
|
||||
#endif
|
||||
|
||||
public class MergeArmatureTests : TestBase
|
||||
{
|
||||
@ -27,6 +30,8 @@ public class MergeArmatureTests : TestBase
|
||||
Assert.NotNull(targetHips.GetChild(1).GetComponent<BoxCollider>());
|
||||
}
|
||||
|
||||
#if MA_VRCSDK3_AVATARS
|
||||
|
||||
[Test]
|
||||
public void DontMergePartiallySamePhysBoneChain()
|
||||
{
|
||||
@ -93,6 +98,8 @@ public class MergeArmatureTests : TestBase
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
private static GameObject LoadShapell()
|
||||
{
|
||||
return GameObject.Instantiate(
|
||||
|
Loading…
Reference in New Issue
Block a user