From 99a4f5420eb216257fb0e09a95bf16e43a82ba93 Mon Sep 17 00:00:00 2001 From: Erimel Date: Fri, 16 Oct 2026 18:58:58 -0400 Subject: [PATCH] Fix VMC tests --- .../dev/slimevr/skeleton/inputprocessors/neck.kt | 1 + .../src/main/java/dev/slimevr/vmc/output-encoder.kt | 12 ++++++------ .../test/java/dev/slimevr/vmc/OutputEncoderTest.kt | 4 +++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/neck.kt b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/neck.kt index c7b26edb0..584a59b93 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/neck.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/neck.kt @@ -7,6 +7,7 @@ import solarxr_protocol.datatypes.BodyPart // Neck bends less when looking up private const val UP_RATIO = 0.75f + // Neck bends slightly more when looking down. private const val DOWN_RATIO = 1.1f diff --git a/server/core/src/main/java/dev/slimevr/vmc/output-encoder.kt b/server/core/src/main/java/dev/slimevr/vmc/output-encoder.kt index 07d9cffe6..eff71136c 100644 --- a/server/core/src/main/java/dev/slimevr/vmc/output-encoder.kt +++ b/server/core/src/main/java/dev/slimevr/vmc/output-encoder.kt @@ -150,7 +150,7 @@ private fun emittedLocalPosition( vmcLocalPosition(bonePosition, parentRotation, parentPosition, parentUnityBone, mirror) } -private fun hipToNeckOffset( +private fun hipToHeadOffset( unityBoneGlobalRotations: MutableMap, unityBoneGlobalPositions: MutableMap, vrm: VrmGeometry?, @@ -188,15 +188,15 @@ private fun vmcHipPosition( val anchoredHipPosition = vrm?.hipPosition ?: Vector3(0f, restHipHeight(bones, skeletonHeight), 0f) if (config.anchorAtHips) return anchoredHipPosition - val neckPosition = unityBoneGlobalPositions[UnityBone.NECK] ?: return anchoredHipPosition - val adjustedNeckPosition = if (config.mirrorTracking) vmcMirrorPosition(neckPosition) else neckPosition + val headPosition = unityBoneGlobalPositions[UnityBone.HEAD] ?: return anchoredHipPosition + val adjustedHeadPosition = if (config.mirrorTracking) vmcMirrorPosition(headPosition) else headPosition val restHeight = vrm?.outputRestHeight ?: skeletonHeight val scale = if (skeletonHeight != 0f) restHeight / skeletonHeight else 1f - val floorRelativeNeck = (adjustedNeckPosition - Vector3(0f, floorLevel, 0f)) * scale + val floorRelativeHead = (adjustedHeadPosition - Vector3(0f, floorLevel, 0f)) * scale - val neckOffset = hipToNeckOffset(unityBoneGlobalRotations, unityBoneGlobalPositions, vrm, config.mirrorTracking) + val headOffset = hipToHeadOffset(unityBoneGlobalRotations, unityBoneGlobalPositions, vrm, config.mirrorTracking) - return floorRelativeNeck - neckOffset + return floorRelativeHead - headOffset } private fun transformMessage(address: String, name: String, pos: Vector3, rot: Quaternion): OscMessage = OscMessage( diff --git a/server/core/src/test/java/dev/slimevr/vmc/OutputEncoderTest.kt b/server/core/src/test/java/dev/slimevr/vmc/OutputEncoderTest.kt index baa806bea..f001d99f2 100644 --- a/server/core/src/test/java/dev/slimevr/vmc/OutputEncoderTest.kt +++ b/server/core/src/test/java/dev/slimevr/vmc/OutputEncoderTest.kt @@ -184,7 +184,7 @@ class OutputEncoderTest { } @Test - fun testFreeAnchorWithoutVrmPlacesHipsFromNeckMinusFloor() { + fun testFreeAnchorWithoutVrmPlacesHipsFromHeadMinusFloor() { val hipHead = Vector3(0f, 0.9f, 0f) val bones = BodyPartMap( mapOf( @@ -192,6 +192,7 @@ class OutputEncoderTest { BodyPart.UPPER_WAIST to bone(BodyPart.UPPER_WAIST, headPosition = Vector3(0f, 1.1f, 0f)), BodyPart.LOWER_CHEST to bone(BodyPart.LOWER_CHEST, headPosition = Vector3(0f, 1.3f, 0f)), BodyPart.NECK to bone(BodyPart.NECK, headPosition = Vector3(0f, 1.5f, 0f)), + BodyPart.HEAD to bone(BodyPart.HEAD, headPosition = Vector3(0f, 1.5f, 0f)), ), ) val config = defaultConfig.copy(anchorAtHips = false) @@ -213,6 +214,7 @@ class OutputEncoderTest { BodyPart.UPPER_WAIST to bone(BodyPart.UPPER_WAIST, headPosition = Vector3(0f, 1.1f, 0f) + shift), BodyPart.LOWER_CHEST to bone(BodyPart.LOWER_CHEST, headPosition = Vector3(0f, 1.3f, 0f) + shift), BodyPart.NECK to bone(BodyPart.NECK, headPosition = Vector3(0f, 1.5f, 0f) + shift), + BodyPart.HEAD to bone(BodyPart.HEAD, headPosition = Vector3(0f, 1.5f, 0f) + shift), ), ) val config = defaultConfig.copy(anchorAtHips = false)