chore: Fix non-VRChat support (for MA 1.10.5) (#1324)

* feat: add version defines for VRCSDK

* chore: early return if VRCSDK project but not VRChat avatar
This commit is contained in:
kaikoga 2024-10-28 02:06:35 +09:00 committed by GitHub
parent 07b648dcc1
commit efa263b551
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
26 changed files with 119 additions and 38 deletions

View File

@ -158,6 +158,7 @@ namespace nadena.dev.modular_avatar.animation
#if MA_VRCSDK3_AVATARS
var avatarDescriptor = context.AvatarDescriptor;
if (!avatarDescriptor) return;
foreach (var layer in avatarDescriptor.baseAnimationLayers)
{

View File

@ -92,6 +92,8 @@ namespace nadena.dev.modular_avatar.animation
public void AddPropertyDefinition(AnimatorControllerParameter paramDef)
{
#if MA_VRCSDK3_AVATARS
if (!_context.AvatarDescriptor) return;
var fx = (AnimatorController)
_context.AvatarDescriptor.baseAnimationLayers
.First(l => l.type == VRCAvatarDescriptor.AnimLayerType.FX)

View File

@ -53,6 +53,8 @@ namespace nadena.dev.modular_avatar.animation
// This helps reduce the risk that we'll accidentally modify the original assets.
#if MA_VRCSDK3_AVATARS
if (!context.AvatarDescriptor) return;
context.AvatarDescriptor.baseAnimationLayers =
CloneLayers(context, context.AvatarDescriptor.baseAnimationLayers);
context.AvatarDescriptor.specialAnimationLayers =

View File

@ -369,21 +369,24 @@ namespace nadena.dev.modular_avatar.animation
Profiler.EndSample();
#if MA_VRCSDK3_AVATARS
var layers = context.AvatarDescriptor.baseAnimationLayers
.Concat(context.AvatarDescriptor.specialAnimationLayers);
Profiler.BeginSample("ApplyMappingsToAvatarMasks");
foreach (var layer in layers)
if (context.AvatarDescriptor)
{
ApplyMappingsToAvatarMask(layer.mask);
var layers = context.AvatarDescriptor.baseAnimationLayers
.Concat(context.AvatarDescriptor.specialAnimationLayers);
if (layer.animatorController is AnimatorController ac)
// By this point, all AnimationOverrideControllers have been collapsed into an ephemeral
// AnimatorController so we can safely modify the controller in-place.
foreach (var acLayer in ac.layers)
ApplyMappingsToAvatarMask(acLayer.avatarMask);
Profiler.BeginSample("ApplyMappingsToAvatarMasks");
foreach (var layer in layers)
{
ApplyMappingsToAvatarMask(layer.mask);
if (layer.animatorController is AnimatorController ac)
// By this point, all AnimationOverrideControllers have been collapsed into an ephemeral
// AnimatorController so we can safely modify the controller in-place.
foreach (var acLayer in ac.layers)
ApplyMappingsToAvatarMask(acLayer.avatarMask);
}
Profiler.EndSample();
}
Profiler.EndSample();
#endif
Profiler.EndSample();

View File

@ -19,6 +19,8 @@ namespace nadena.dev.modular_avatar.core.editor
internal static void FixupExpressionsMenu(BuildContext context)
{
if (!context.AvatarDescriptor) return;
context.AvatarDescriptor.customExpressions = true;
var expressionsMenu = context.AvatarDescriptor.expressionsMenu;

View File

@ -65,6 +65,7 @@ namespace nadena.dev.modular_avatar.core.editor
mergeSessions.Clear();
var descriptor = avatarGameObject.GetComponent<VRCAvatarDescriptor>();
if (!descriptor) return;
if (descriptor.baseAnimationLayers != null) InitSessions(descriptor.baseAnimationLayers);
if (descriptor.specialAnimationLayers != null) InitSessions(descriptor.specialAnimationLayers);

View File

@ -9,6 +9,8 @@ namespace nadena.dev.modular_avatar.core.editor
{
protected override void Execute(ndmf.BuildContext context)
{
if (!context.AvatarDescriptor) return;
var expParams = context.AvatarDescriptor.expressionParameters;
if (expParams != null && context.IsTemporaryAsset(expParams))
{

View File

@ -34,6 +34,8 @@ namespace nadena.dev.modular_avatar.core.editor
internal void Execute()
{
if (!context.AvatarDescriptor) return;
// 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.
_writeDefaults = MergeAnimatorProcessor.ProbeWriteDefaults(FindFxController().animatorController as AnimatorController) ?? true;

View File

@ -159,6 +159,8 @@ namespace nadena.dev.modular_avatar.core.editor
public void OnPreprocessAvatar(GameObject avatar, BuildContext context)
{
if (!context.AvatarDescriptor) return;
_context = context;
var syncParams = WalkTree(avatar);

View File

@ -1,4 +1,6 @@
using nadena.dev.modular_avatar.core.editor;
#if MA_VRCSDK3_AVATARS
using nadena.dev.modular_avatar.core.editor;
using NUnit.Framework;
using UnityEditor;
using UnityEngine;
@ -36,4 +38,6 @@ namespace modular_avatar_tests
Assert.AreEqual("x", curves[0].propertyName);
}
}
}
}
#endif

View File

@ -1,4 +1,6 @@
using System;
#if MA_VRCSDK3_AVATARS
using System;
using System.Collections.Generic;
using System.Linq;
using nadena.dev.ndmf;
@ -158,4 +160,6 @@ namespace modular_avatar_tests
Assert.IsFalse(state.transformMaskElements.Any(e => e.Item1 == "Armature/Hips/UpperLeg.R"));
}
}
}
}
#endif

View File

@ -1,4 +1,6 @@
using System.Linq;
#if MA_VRCSDK3_AVATARS
using System.Linq;
using nadena.dev.ndmf;
using NUnit.Framework;
using UnityEditor.Animations;
@ -26,4 +28,6 @@ namespace modular_avatar_tests
Assert.AreEqual(desiredIndex, alc.layer);
}
}
}
}
#endif

View File

@ -1,9 +1,10 @@
using nadena.dev.modular_avatar.core.editor;
#if MA_VRCSDK3_AVATARS_3_5_2_OR_NEWER
using nadena.dev.modular_avatar.core.editor;
using NUnit.Framework;
using UnityEditor.Animations;
using VRC.SDK3.Avatars.Components;
#if MA_VRCSDK3_AVATARS_3_5_2_OR_NEWER
namespace modular_avatar_tests
{
public class PlayAudioRemapping : TestBase
@ -28,4 +29,5 @@ namespace modular_avatar_tests
}
}
}
#endif

View File

@ -1,4 +1,6 @@
using modular_avatar_tests;
#if MA_VRCSDK3_AVATARS
using modular_avatar_tests;
using nadena.dev.modular_avatar.animation;
using nadena.dev.modular_avatar.core;
using nadena.dev.modular_avatar.core.editor;
@ -47,4 +49,6 @@ namespace UnitTests.MergeAnimatorTests
Assert.IsTrue(state.motion.name.StartsWith("Anim2"));
}
}
}
}
#endif

View File

@ -1,3 +1,5 @@
#if MA_VRCSDK3_AVATARS
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
@ -35,3 +37,4 @@ public class PreexistingParamsTest : TestBase
}
}
#endif

View File

@ -1,4 +1,6 @@
using modular_avatar_tests;
#if MA_VRCSDK3_AVATARS
using modular_avatar_tests;
using nadena.dev.modular_avatar.core;
using nadena.dev.modular_avatar.core.editor;
using NUnit.Framework;
@ -25,4 +27,6 @@ namespace UnitTests.MergeAnimatorTests.ProxyAnim
Assert.AreEqual(originalClip, resultClip);
}
}
}
}
#endif

View File

@ -1,4 +1,6 @@
using modular_avatar_tests;
#if MA_VRCSDK3_AVATARS
using modular_avatar_tests;
using nadena.dev.ndmf;
using NUnit.Framework;
using UnityEditor.Animations;
@ -38,4 +40,6 @@ namespace UnitTests.MergeAnimatorTests.SyncedLayerOverrideInSubStatemachine
Assert.NotNull(motion);
}
}
}
}
#endif

View File

@ -1,3 +1,5 @@
#if MA_VRCSDK3_AVATARS
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
@ -268,3 +270,4 @@ public class ConvertTransitionTypes : TestBase
}
}
#endif

View File

@ -1,3 +1,5 @@
#if MA_VRCSDK3_AVATARS
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
@ -24,3 +26,5 @@ public class MergeDirectBlendTreeTests : TestBase
Assert.AreEqual(0, parameters["DEF"]);
}
}
#endif

View File

@ -1,4 +1,6 @@
using System.Linq;
#if MA_VRCSDK3_AVATARS
using System.Linq;
using modular_avatar_tests;
using nadena.dev.modular_avatar.core.editor;
using NUnit.Framework;
@ -58,4 +60,6 @@ namespace UnitTests.ReactiveComponent
Assert.AreEqual(m3.actionGroups, m1.actionGroups);
}
}
}
}
#endif

View File

@ -1,4 +1,6 @@
using System.Linq;
#if MA_VRCSDK3_AVATARS
using System.Linq;
using modular_avatar_tests;
using nadena.dev.modular_avatar.core;
using nadena.dev.modular_avatar.core.editor;
@ -47,4 +49,6 @@ namespace UnitTests.ReactiveComponent
Assert.IsFalse(obj.activeSelf);
}
}
}
}
#endif

View File

@ -1,4 +1,6 @@
using System;
#if MA_VRCSDK3_AVATARS
using System;
using System.Collections.Generic;
using System.Linq;
using modular_avatar_tests;
@ -112,4 +114,6 @@ namespace UnitTests.ReactiveComponent.ParameterAssignment
Assert.AreEqual(expectedDefaultValue, avDesc.expressionParameters.parameters.Single().defaultValue);
}
}
}
}
#endif

View File

@ -1,4 +1,6 @@
using System;
#if MA_VRCSDK3_AVATARS
using System;
using System.Linq;
using modular_avatar_tests;
using nadena.dev.modular_avatar.core;
@ -82,4 +84,6 @@ namespace UnitTests.ReactiveComponent.ParameterAssignment
Assert.AreEqual(expected, descriptor.expressionParameters.parameters.Single().valueType);
}
}
}
}
#endif

View File

@ -1,3 +1,5 @@
#if MA_VRCSDK3_AVATARS
using System.Collections;
using System.Collections.Generic;
using System.Linq;
@ -96,3 +98,5 @@ public class ShapeDeletionAnalysis : TestBase
Assert.AreEqual(originalSharedMesh, mesh.sharedMesh);
}
}
#endif

View File

@ -1,4 +1,6 @@
using modular_avatar_tests;
#if MA_VRCSDK3_AVATARS
using modular_avatar_tests;
using nadena.dev.modular_avatar.animation;
using nadena.dev.modular_avatar.core.editor;
using NUnit.Framework;
@ -121,4 +123,6 @@ namespace ShapeChangerTests
Assert.AreEqual(100.0f, smr.GetBlendShapeWeight(sharedMesh.GetBlendShapeIndex("key3")), 0.1f);
}
}
}
}
#endif

View File

@ -1,4 +1,6 @@
using System.Collections.Generic;
#if MA_VRCSDK3_AVATARS
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@ -57,4 +59,6 @@ namespace UnitTests.VisibleHeadAccessoryTest
Assert.AreEqual(headchop.globalScaleFactor, 1);
}
}
}
}
#endif