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": { "locked": {
"com.vrchat.avatars": { "com.vrchat.avatars": {
"version": "3.5.0", "version": "3.6.1",
"dependencies": { "dependencies": {
"com.vrchat.base": "3.5.0" "com.vrchat.base": "3.6.1"
} }
}, },
"com.vrchat.base": { "com.vrchat.base": {
"version": "3.5.0", "version": "3.6.1",
"dependencies": {} "dependencies": {}
}, },
"nadena.dev.ndmf": { "nadena.dev.ndmf": {

View File

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

View File

@ -8,6 +8,7 @@ using NUnit.Framework;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
using UnityEngine.Animations; using UnityEngine.Animations;
using VRC.SDK3.Avatars.Components;
namespace UnitTests.VisibleHeadAccessoryTest namespace UnitTests.VisibleHeadAccessoryTest
{ {
@ -36,9 +37,9 @@ namespace UnitTests.VisibleHeadAccessoryTest
{ {
"Armature/Hips/Spine/Chest/Neck/Head/O1", "Armature/Hips/Spine/Chest/Neck/Head/O1",
"Armature/Hips/Spine/Chest/Neck/Head/O1/O2", "Armature/Hips/Spine/Chest/Neck/Head/O1/O2",
"Armature/Hips/Spine/Chest/Neck/Head (FirstPersonVisible)/O1", "Armature/Hips/Spine/Chest/Neck/Head/Head (HeadChop)/O1",
"Armature/Hips/Spine/Chest/Neck/Head (FirstPersonVisible)/O1/O2", "Armature/Hips/Spine/Chest/Neck/Head/Head (HeadChop)/O1/O2",
"Armature/Hips/Spine/Chest/Neck/Head (FirstPersonVisible)/O1/O2/Cube", "Armature/Hips/Spine/Chest/Neck/Head/Head (HeadChop)/O1/O2/Cube",
}.ToImmutableSortedSet(); }.ToImmutableSortedSet();
var bindings = AnimationUtility.GetCurveBindings(fx_anim).Select(binding => binding.path) var bindings = AnimationUtility.GetCurveBindings(fx_anim).Select(binding => binding.path)
@ -46,13 +47,14 @@ namespace UnitTests.VisibleHeadAccessoryTest
Assert.AreEqual(expectedBindings, bindings); Assert.AreEqual(expectedBindings, bindings);
var head = prefab.transform.Find("Armature/Hips/Spine/Chest/Neck/Head"); var head = prefab.transform.Find("Armature/Hips/Spine/Chest/Neck/Head");
var constraint = prefab.transform.Find("Armature/Hips/Spine/Chest/Neck/Head (FirstPersonVisible)") var chop = head.Find("Head (HeadChop)");
.GetComponent<ParentConstraint>(); var headchop = chop.GetComponent<VRCHeadChop>();
Assert.AreEqual(head, constraint.GetSource(0).sourceTransform); Assert.AreEqual(headchop.targetBones.Length, 1);
Assert.AreEqual(1, constraint.GetSource(0).weight); Assert.AreEqual(headchop.targetBones[0].transform, chop);
Assert.AreEqual(new Vector3(0, 0, 0), constraint.translationOffsets[0]); Assert.AreEqual(headchop.targetBones[0].scaleFactor, 1);
Assert.AreEqual(new Vector3(0, 0, 0), constraint.rotationOffsets[0]); 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" "com.unity.nuget.newtonsoft-json": "2.0.0"
}, },
"vpmDependencies": { "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" "nadena.dev.ndmf": ">=1.5.0-beta.3 <2.0.0-a"
} }
} }