From 3d3aefd4f93afbbdd1bcf46f0a7850dadf4d6cb9 Mon Sep 17 00:00:00 2001 From: bd_ Date: Tue, 6 Aug 2024 05:53:37 -0700 Subject: [PATCH] feat: use VRCHeadChop for VisibleHeadAccessory (#954) Closes: #784 --- .github/ProjectRoot/vpm-manifest-2022.json | 6 ++--- Editor/VisibleHeadAccessoryProcessor.cs | 25 ++++++++++--------- .../VisibleHeadAccessoryTest.cs | 20 ++++++++------- package.json | 2 +- 4 files changed, 28 insertions(+), 25 deletions(-) diff --git a/.github/ProjectRoot/vpm-manifest-2022.json b/.github/ProjectRoot/vpm-manifest-2022.json index e2bb6817..1be7eb3c 100644 --- a/.github/ProjectRoot/vpm-manifest-2022.json +++ b/.github/ProjectRoot/vpm-manifest-2022.json @@ -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": { diff --git a/Editor/VisibleHeadAccessoryProcessor.cs b/Editor/VisibleHeadAccessoryProcessor.cs index dad2a4c0..dbb9685d 100644 --- a/Editor/VisibleHeadAccessoryProcessor.cs +++ b/Editor/VisibleHeadAccessoryProcessor.cs @@ -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(); - constraint.AddSource(new ConstraintSource() + var headChop = obj.AddComponent(); + 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; diff --git a/UnitTests~/VisibleHeadAccessoryTest/VisibleHeadAccessoryTest.cs b/UnitTests~/VisibleHeadAccessoryTest/VisibleHeadAccessoryTest.cs index 147de6c8..a85f2954 100644 --- a/UnitTests~/VisibleHeadAccessoryTest/VisibleHeadAccessoryTest.cs +++ b/UnitTests~/VisibleHeadAccessoryTest/VisibleHeadAccessoryTest.cs @@ -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(); + var chop = head.Find("Head (HeadChop)"); + var headchop = chop.GetComponent(); - 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); } } } \ No newline at end of file diff --git a/package.json b/package.json index f2988e02..b274d70c 100644 --- a/package.json +++ b/package.json @@ -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" } }