From 4e84ebdfc9cc52f3e20e8cd17a27dd1644b4d691 Mon Sep 17 00:00:00 2001 From: Erimel Date: Mon, 16 Nov 2026 19:59:44 -0500 Subject: [PATCH] upper leg twist as post processing --- .../upper-legs-twist.kt | 19 +++++++++++-------- .../main/java/dev/slimevr/skeleton/module.kt | 4 ++-- 2 files changed, 13 insertions(+), 10 deletions(-) rename server/core/src/main/java/dev/slimevr/skeleton/{inputprocessors => computedprocessors}/upper-legs-twist.kt (62%) diff --git a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/upper-legs-twist.kt b/server/core/src/main/java/dev/slimevr/skeleton/computedprocessors/upper-legs-twist.kt similarity index 62% rename from server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/upper-legs-twist.kt rename to server/core/src/main/java/dev/slimevr/skeleton/computedprocessors/upper-legs-twist.kt index de88807ad..b4355ced9 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/upper-legs-twist.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/computedprocessors/upper-legs-twist.kt @@ -1,7 +1,9 @@ -package dev.slimevr.skeleton.inputprocessors +package dev.slimevr.skeleton.computedprocessors import dev.slimevr.config.Settings +import dev.slimevr.skeleton.ComputedSkeleton import dev.slimevr.skeleton.InputSkeleton +import dev.slimevr.skeleton.SkeletonComputedProcessor import dev.slimevr.skeleton.SkeletonInputProcessor import io.github.axisangles.ktmath.Quaternion import io.github.axisangles.ktmath.Vector3 @@ -22,9 +24,11 @@ private fun alignRoll(from: Quaternion, to: Quaternion): Quaternion { } /** - * Handles rotating the upper legs' roll to match the lower legs' roll. + * Handles rotating the upper legs' roll to match the lower legs' roll to make VRChat's knee IK work better. + * + * This is a computed processor running after IK because we want to use the real upper leg's twist for IK and constraints. */ -class UpperLegsTwistInputProcessor(val settings: Settings) : SkeletonInputProcessor { +class UpperLegsTwistComputedProcessor(val settings: Settings) : SkeletonComputedProcessor { /** * First value is the BodyPart to be aligned. * Second value is the source BodyPart. @@ -34,18 +38,17 @@ class UpperLegsTwistInputProcessor(val settings: Settings) : SkeletonInputProces BodyPart.RIGHT_UPPER_LEG to BodyPart.RIGHT_LOWER_LEG, ) - override fun process(mutableInputSkeleton: InputSkeleton, skeletonHeight: Float) { + override fun process(mutableComputedSkeleton: ComputedSkeleton, inputSkeleton: InputSkeleton) { val ratio = settings.context.state.value.data.skeletonConfig.ratios.interpolateUpperLegsTwistWithLowerLegs if (ratio == 0f) return // Upper legs are written, lower legs are read, so the two never overlap for (bodyPartToSource in bodyPartToSources) { - val bone = mutableInputSkeleton[bodyPartToSource.first] ?: continue - if (!bone.isRotationActive) continue + val bone = mutableComputedSkeleton[bodyPartToSource.first] ?: continue + val sourceRotation = mutableComputedSkeleton[bodyPartToSource.second]?.rotation ?: continue - val sourceRotation = mutableInputSkeleton[bodyPartToSource.second]?.rotation ?: continue val alignedRotation = alignRoll(bone.rotation, sourceRotation) - mutableInputSkeleton[bodyPartToSource.first] = bone.copy(rotation = bone.rotation.interpR(alignedRotation, ratio)) + mutableComputedSkeleton[bodyPartToSource.first] = bone.copy(rotation = bone.rotation.interpR(alignedRotation, ratio)) } } } diff --git a/server/core/src/main/java/dev/slimevr/skeleton/module.kt b/server/core/src/main/java/dev/slimevr/skeleton/module.kt index 1ca762ed8..1a7e5b7e2 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/module.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/module.kt @@ -4,6 +4,7 @@ import dev.slimevr.Phase1ContextProvider import dev.slimevr.config.Settings import dev.slimevr.context.Behaviour import dev.slimevr.context.Context +import dev.slimevr.skeleton.computedprocessors.UpperLegsTwistComputedProcessor import dev.slimevr.skeleton.computedprocessors.VelocityComputedProcessor import dev.slimevr.skeleton.fkprocessors.FootPlantFkProcessor import dev.slimevr.skeleton.fkprocessors.LocalizerFkProcessor @@ -19,7 +20,6 @@ import dev.slimevr.skeleton.inputprocessors.HeadPositionFallbackInputProcessor import dev.slimevr.skeleton.inputprocessors.NeckInputProcessor import dev.slimevr.skeleton.inputprocessors.SpineInputProcessor import dev.slimevr.skeleton.inputprocessors.ToesInputProcessor -import dev.slimevr.skeleton.inputprocessors.UpperLegsTwistInputProcessor import dev.slimevr.skeleton.targetprocessors.FloorClipTargetProcessor import dev.slimevr.skeleton.targetprocessors.PositionalTargetProcessor import dev.slimevr.skeleton.targetprocessors.SkatingCorrectionTargetProcessor @@ -285,7 +285,6 @@ class Skeleton( FingersInputProcessor(), ToesInputProcessor(), ConstraintInputProcessor(settings), - UpperLegsTwistInputProcessor(settings), ), // Run on the result of FK and persist fkComputedProcessors = listOf( @@ -305,6 +304,7 @@ class Skeleton( ), // Run on the result of IK and persist. ikComputedProcessors = listOf( + UpperLegsTwistComputedProcessor(settings), VelocityComputedProcessor(), ), ),