mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-01-31 02:32:53 +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.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if MA_VRCSDK3_AVATARS
|
|
||||||
#endif
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -34,9 +32,12 @@ using nadena.dev.ndmf.util;
|
|||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEditor.Animations;
|
using UnityEditor.Animations;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
|
#if MA_VRCSDK3_AVATARS
|
||||||
using VRC.SDK3.Avatars.Components;
|
using VRC.SDK3.Avatars.Components;
|
||||||
using VRC.SDKBase;
|
using VRC.SDKBase;
|
||||||
using Object = UnityEngine.Object;
|
#endif
|
||||||
|
|
||||||
namespace nadena.dev.modular_avatar.animation
|
namespace nadena.dev.modular_avatar.animation
|
||||||
{
|
{
|
||||||
@ -64,7 +65,9 @@ namespace nadena.dev.modular_avatar.animation
|
|||||||
|
|
||||||
private int _controllerBaseLayer = 0;
|
private int _controllerBaseLayer = 0;
|
||||||
|
|
||||||
|
#if MA_VRCSDK3_AVATARS
|
||||||
public VRC_AnimatorLayerControl.BlendableLayer? BlendableLayer;
|
public VRC_AnimatorLayerControl.BlendableLayer? BlendableLayer;
|
||||||
|
#endif
|
||||||
|
|
||||||
public AnimatorCombiner(ndmf.BuildContext context, String assetName)
|
public AnimatorCombiner(ndmf.BuildContext context, String assetName)
|
||||||
{
|
{
|
||||||
@ -134,23 +137,27 @@ namespace nadena.dev.modular_avatar.animation
|
|||||||
var newBehaviors = new List<StateMachineBehaviour>();
|
var newBehaviors = new List<StateMachineBehaviour>();
|
||||||
foreach (var b in behaviours)
|
foreach (var b in behaviours)
|
||||||
{
|
{
|
||||||
if (b is VRCAnimatorLayerControl alc && alc.playable == BlendableLayer)
|
switch (b)
|
||||||
{
|
{
|
||||||
int newLayer = -1;
|
#if MA_VRCSDK3_AVATARS
|
||||||
if (alc.layer >= 0 && alc.layer < layerIndexMappings.Length)
|
case VRCAnimatorLayerControl alc when alc.playable == BlendableLayer:
|
||||||
{
|
int newLayer = -1;
|
||||||
newLayer = layerIndexMappings[alc.layer];
|
if (alc.layer >= 0 && alc.layer < layerIndexMappings.Length)
|
||||||
}
|
{
|
||||||
|
newLayer = layerIndexMappings[alc.layer];
|
||||||
|
}
|
||||||
|
|
||||||
if (newLayer != -1)
|
if (newLayer != -1)
|
||||||
{
|
{
|
||||||
alc.layer = newLayer;
|
alc.layer = newLayer;
|
||||||
newBehaviors.Add(alc);
|
newBehaviors.Add(alc);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
break;
|
||||||
{
|
#endif
|
||||||
newBehaviors.Add(b);
|
default:
|
||||||
|
newBehaviors.Add(b);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
|
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using static nadena.dev.modular_avatar.core.editor.Localization;
|
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 UnityEditor.Animations;
|
||||||
using static nadena.dev.modular_avatar.core.editor.Localization;
|
using static nadena.dev.modular_avatar.core.editor.Localization;
|
||||||
|
|
||||||
@ -34,4 +36,6 @@ namespace nadena.dev.modular_avatar.core.editor
|
|||||||
ShowLanguageUI();
|
ShowLanguageUI();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -46,7 +46,9 @@ namespace nadena.dev.modular_avatar.core.editor
|
|||||||
|
|
||||||
private ndmf.BuildContext frameworkContext;
|
private ndmf.BuildContext frameworkContext;
|
||||||
private BuildContext context;
|
private BuildContext context;
|
||||||
|
#if MA_VRCSDK3_AVATARS
|
||||||
private Dictionary<Transform, VRCPhysBoneBase> physBoneByRootBone;
|
private Dictionary<Transform, VRCPhysBoneBase> physBoneByRootBone;
|
||||||
|
#endif
|
||||||
private BoneDatabase BoneDatabase = new BoneDatabase();
|
private BoneDatabase BoneDatabase = new BoneDatabase();
|
||||||
|
|
||||||
private PathMappings PathMappings => frameworkContext.Extension<AnimationServicesContext>()
|
private PathMappings PathMappings => frameworkContext.Extension<AnimationServicesContext>()
|
||||||
@ -60,9 +62,11 @@ namespace nadena.dev.modular_avatar.core.editor
|
|||||||
{
|
{
|
||||||
this.frameworkContext = context;
|
this.frameworkContext = context;
|
||||||
this.context = context.Extension<ModularAvatarContext>().BuildContext;
|
this.context = context.Extension<ModularAvatarContext>().BuildContext;
|
||||||
|
#if MA_VRCSDK3_AVATARS
|
||||||
physBoneByRootBone = new Dictionary<Transform, VRCPhysBoneBase>();
|
physBoneByRootBone = new Dictionary<Transform, VRCPhysBoneBase>();
|
||||||
foreach (var physbone in avatarGameObject.transform.GetComponentsInChildren<VRCPhysBoneBase>(true))
|
foreach (var physbone in avatarGameObject.transform.GetComponentsInChildren<VRCPhysBoneBase>(true))
|
||||||
physBoneByRootBone[physbone.GetRootTransform()] = physbone;
|
physBoneByRootBone[physbone.GetRootTransform()] = physbone;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (avatarGameObject.TryGetComponent<Animator>(out var animator) && animator.isHuman)
|
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)
|
private bool NotAffectedByPhysBoneOrSimilarChainsAsTarget(Transform child, Transform target)
|
||||||
{
|
{
|
||||||
|
#if MA_VRCSDK3_AVATARS
|
||||||
// not affected
|
// not affected
|
||||||
if (!physBoneByRootBone.TryGetValue(child, out VRCPhysBoneBase physBone)) return true;
|
if (!physBoneByRootBone.TryGetValue(child, out VRCPhysBoneBase physBone)) return true;
|
||||||
|
|
||||||
var ignores = new HashSet<Transform>(physBone.ignoreTransforms.Where(x => x));
|
var ignores = new HashSet<Transform>(physBone.ignoreTransforms.Where(x => x));
|
||||||
|
|
||||||
return IsSimilarChainInPosition(child, target, ignores);
|
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.
|
// 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 System.Collections.Generic;
|
||||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||||
using nadena.dev.modular_avatar.animation;
|
using nadena.dev.modular_avatar.animation;
|
||||||
@ -168,4 +170,6 @@ namespace nadena.dev.modular_avatar.core.editor
|
|||||||
return _rootBlendTree;
|
return _rootBlendTree;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -1,4 +1,6 @@
|
|||||||
using System.Linq;
|
#if MA_VRCSDK3_AVATARS
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
using nadena.dev.ndmf;
|
using nadena.dev.ndmf;
|
||||||
|
|
||||||
namespace nadena.dev.modular_avatar.core.editor
|
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);
|
UnityEngine.Object.DestroyImmediate(component);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
#if MA_VRCSDK3_AVATARS
|
||||||
seq.Run(PruneParametersPass.Instance);
|
seq.Run(PruneParametersPass.Instance);
|
||||||
|
#endif
|
||||||
});
|
});
|
||||||
|
|
||||||
InPhase(BuildPhase.Optimizing)
|
InPhase(BuildPhase.Optimizing)
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
"precompiledReferences": [
|
"precompiledReferences": [
|
||||||
"Newtonsoft.Json.dll",
|
"Newtonsoft.Json.dll",
|
||||||
"System.Collections.Immutable.dll",
|
"System.Collections.Immutable.dll",
|
||||||
|
"System.Memory.dll",
|
||||||
"VRCSDKBase.dll",
|
"VRCSDKBase.dll",
|
||||||
"VRCSDKBase-Editor.dll",
|
"VRCSDKBase-Editor.dll",
|
||||||
"VRCSDK3A.dll",
|
"VRCSDK3A.dll",
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
using UnityEngine;
|
#if MA_VRCSDK3_AVATARS
|
||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace nadena.dev.modular_avatar.core
|
namespace nadena.dev.modular_avatar.core
|
||||||
{
|
{
|
||||||
@ -11,4 +13,6 @@ namespace nadena.dev.modular_avatar.core
|
|||||||
public MergeAnimatorPathMode PathMode = MergeAnimatorPathMode.Relative;
|
public MergeAnimatorPathMode PathMode = MergeAnimatorPathMode.Relative;
|
||||||
public AvatarObjectReference RelativePathRoot = new AvatarObjectReference();
|
public AvatarObjectReference RelativePathRoot = new AvatarObjectReference();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -152,7 +152,7 @@ namespace nadena.dev.modular_avatar.core
|
|||||||
|
|
||||||
var oldPatches = new HashSet<ScalePatch>(this.patches);
|
var oldPatches = new HashSet<ScalePatch>(this.patches);
|
||||||
var newPatches = new HashSet<ScalePatch>();
|
var newPatches = new HashSet<ScalePatch>();
|
||||||
var avatarRoot = RuntimeUtil.FindAvatarInParents(selfTransform);
|
var avatarRoot = RuntimeUtil.FindAvatarTransformInParents(selfTransform);
|
||||||
|
|
||||||
if (avatarRoot != null)
|
if (avatarRoot != null)
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
using System.Collections;
|
#if MA_VRCSDK3_AVATARS
|
||||||
|
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using modular_avatar_tests;
|
using modular_avatar_tests;
|
||||||
using nadena.dev.modular_avatar.core.editor;
|
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);
|
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 System.Linq;
|
||||||
using nadena.dev.modular_avatar.core;
|
using nadena.dev.modular_avatar.core;
|
||||||
using nadena.dev.modular_avatar.core.editor;
|
using nadena.dev.modular_avatar.core.editor;
|
||||||
@ -125,4 +127,6 @@ namespace modular_avatar_tests
|
|||||||
return merge;
|
return merge;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -1,4 +1,6 @@
|
|||||||
using System.Linq;
|
#if MA_VRCSDK3_AVATARS
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
using nadena.dev.ndmf;
|
using nadena.dev.ndmf;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using UnityEditor.Animations;
|
using UnityEditor.Animations;
|
||||||
@ -25,4 +27,6 @@ namespace modular_avatar_tests
|
|||||||
}, layerNames);
|
}, layerNames);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -3,7 +3,6 @@ using modular_avatar_tests;
|
|||||||
using nadena.dev.modular_avatar.core.editor;
|
using nadena.dev.modular_avatar.core.editor;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using VRC.SDK3.Avatars.Components;
|
|
||||||
|
|
||||||
public class PreferFirstHipsMatch : TestBase
|
public class PreferFirstHipsMatch : TestBase
|
||||||
{
|
{
|
||||||
@ -11,7 +10,9 @@ public class PreferFirstHipsMatch : TestBase
|
|||||||
public void SetupHeuristicPrefersFirstHipsMatch()
|
public void SetupHeuristicPrefersFirstHipsMatch()
|
||||||
{
|
{
|
||||||
var root = CreateCommonPrefab("shapell.fbx");
|
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_hips = root.GetComponent<Animator>().GetBoneTransform(HumanBodyBones.Hips).gameObject;
|
||||||
var root_armature = root_hips.transform.parent.gameObject;
|
var root_armature = root_hips.transform.parent.gameObject;
|
||||||
var root_secondary = CreateChild(root, "PBC");
|
var root_secondary = CreateChild(root, "PBC");
|
||||||
@ -26,4 +27,4 @@ public class PreferFirstHipsMatch : TestBase
|
|||||||
Assert.AreSame(root_hips, det_av_hips);
|
Assert.AreSame(root_hips, det_av_hips);
|
||||||
Assert.AreSame(outfit_hips, det_outfit_hips);
|
Assert.AreSame(outfit_hips, det_outfit_hips);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,12 @@ using nadena.dev.modular_avatar.core.editor;
|
|||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using ModularAvatarMergeArmature = nadena.dev.modular_avatar.core.ModularAvatarMergeArmature;
|
||||||
|
|
||||||
|
#if MA_VRCSDK3_AVATARS
|
||||||
using VRC.SDK3.Avatars.Components;
|
using VRC.SDK3.Avatars.Components;
|
||||||
using VRC.SDK3.Dynamics.PhysBone.Components;
|
using VRC.SDK3.Dynamics.PhysBone.Components;
|
||||||
using ModularAvatarMergeArmature = nadena.dev.modular_avatar.core.ModularAvatarMergeArmature;
|
#endif
|
||||||
|
|
||||||
public class MergeArmatureTests : TestBase
|
public class MergeArmatureTests : TestBase
|
||||||
{
|
{
|
||||||
@ -27,6 +30,8 @@ public class MergeArmatureTests : TestBase
|
|||||||
Assert.NotNull(targetHips.GetChild(1).GetComponent<BoxCollider>());
|
Assert.NotNull(targetHips.GetChild(1).GetComponent<BoxCollider>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if MA_VRCSDK3_AVATARS
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void DontMergePartiallySamePhysBoneChain()
|
public void DontMergePartiallySamePhysBoneChain()
|
||||||
{
|
{
|
||||||
@ -93,6 +98,8 @@ public class MergeArmatureTests : TestBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
private static GameObject LoadShapell()
|
private static GameObject LoadShapell()
|
||||||
{
|
{
|
||||||
return GameObject.Instantiate(
|
return GameObject.Instantiate(
|
||||||
|
Loading…
Reference in New Issue
Block a user