feat: use VRCHeadChop for VisibleHeadAccessory (#954)

Closes: #784
This commit is contained in:
bd_ 2024-08-06 05:53:37 -07:00 committed by GitHub
parent 9a974f5f09
commit 3d3aefd4f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 28 additions and 25 deletions

View File

@ -9,13 +9,13 @@
},
"locked": {
"com.vrchat.avatars": {
"version": "3.5.0",
"version": "3.6.1",
"dependencies": {
"com.vrchat.base": "3.5.0"
"com.vrchat.base": "3.6.1"
}
},
"com.vrchat.base": {
"version": "3.5.0",
"version": "3.6.1",
"dependencies": {}
},
"nadena.dev.ndmf": {

View File

@ -6,7 +6,7 @@ using System.Collections.Immutable;
using nadena.dev.modular_avatar.editor.ErrorReporting;
using UnityEditor;
using UnityEngine;
using UnityEngine.Animations;
using VRC.SDK3.Avatars.Components;
using Object = UnityEngine.Object;
#if MA_VRCSDK3_AVATARS
@ -226,9 +226,9 @@ namespace nadena.dev.modular_avatar.core.editor
if (_proxyHead != null) return _proxyHead;
var src = _headBone;
GameObject obj = new GameObject(src.name + " (FirstPersonVisible)");
var obj = new GameObject(src.name + " (HeadChop)");
Transform parent = _headBone.parent;
var parent = _headBone;
obj.transform.SetParent(parent, false);
obj.transform.localPosition = src.localPosition;
@ -236,16 +236,17 @@ namespace nadena.dev.modular_avatar.core.editor
obj.transform.localScale = src.localScale;
Debug.Log($"src.localScale = {src.localScale} obj.transform.localScale = {obj.transform.localScale}");
var constraint = obj.AddComponent<ParentConstraint>();
constraint.AddSource(new ConstraintSource()
var headChop = obj.AddComponent<VRCHeadChop>();
headChop.targetBones = new[]
{
weight = 1.0f,
sourceTransform = src
});
constraint.constraintActive = true;
constraint.locked = true;
constraint.rotationOffsets = new[] {Vector3.zero};
constraint.translationOffsets = new[] {Vector3.zero};
new VRCHeadChop.HeadChopBone
{
transform = obj.transform,
applyCondition = VRCHeadChop.HeadChopBone.ApplyCondition.AlwaysApply,
scaleFactor = 1
}
};
headChop.globalScaleFactor = 1;
_proxyHead = obj.transform;

View File

@ -8,6 +8,7 @@ using NUnit.Framework;
using UnityEditor;
using UnityEngine;
using UnityEngine.Animations;
using VRC.SDK3.Avatars.Components;
namespace UnitTests.VisibleHeadAccessoryTest
{
@ -36,9 +37,9 @@ namespace UnitTests.VisibleHeadAccessoryTest
{
"Armature/Hips/Spine/Chest/Neck/Head/O1",
"Armature/Hips/Spine/Chest/Neck/Head/O1/O2",
"Armature/Hips/Spine/Chest/Neck/Head (FirstPersonVisible)/O1",
"Armature/Hips/Spine/Chest/Neck/Head (FirstPersonVisible)/O1/O2",
"Armature/Hips/Spine/Chest/Neck/Head (FirstPersonVisible)/O1/O2/Cube",
"Armature/Hips/Spine/Chest/Neck/Head/Head (HeadChop)/O1",
"Armature/Hips/Spine/Chest/Neck/Head/Head (HeadChop)/O1/O2",
"Armature/Hips/Spine/Chest/Neck/Head/Head (HeadChop)/O1/O2/Cube",
}.ToImmutableSortedSet();
var bindings = AnimationUtility.GetCurveBindings(fx_anim).Select(binding => binding.path)
@ -46,13 +47,14 @@ namespace UnitTests.VisibleHeadAccessoryTest
Assert.AreEqual(expectedBindings, bindings);
var head = prefab.transform.Find("Armature/Hips/Spine/Chest/Neck/Head");
var constraint = prefab.transform.Find("Armature/Hips/Spine/Chest/Neck/Head (FirstPersonVisible)")
.GetComponent<ParentConstraint>();
var chop = head.Find("Head (HeadChop)");
var headchop = chop.GetComponent<VRCHeadChop>();
Assert.AreEqual(head, constraint.GetSource(0).sourceTransform);
Assert.AreEqual(1, constraint.GetSource(0).weight);
Assert.AreEqual(new Vector3(0, 0, 0), constraint.translationOffsets[0]);
Assert.AreEqual(new Vector3(0, 0, 0), constraint.rotationOffsets[0]);
Assert.AreEqual(headchop.targetBones.Length, 1);
Assert.AreEqual(headchop.targetBones[0].transform, chop);
Assert.AreEqual(headchop.targetBones[0].scaleFactor, 1);
Assert.AreEqual(headchop.targetBones[0].applyCondition, VRCHeadChop.HeadChopBone.ApplyCondition.AlwaysApply);
Assert.AreEqual(headchop.globalScaleFactor, 1);
}
}
}

View File

@ -15,7 +15,7 @@
"com.unity.nuget.newtonsoft-json": "2.0.0"
},
"vpmDependencies": {
"com.vrchat.avatars": ">=3.4.0",
"com.vrchat.avatars": ">=3.6.1",
"nadena.dev.ndmf": ">=1.5.0-beta.3 <2.0.0-a"
}
}