From 714f8cbca4428aa8f80d7e3403ff093712990a08 Mon Sep 17 00:00:00 2001 From: Erimel Date: Fri, 23 Oct 2026 18:34:51 -0400 Subject: [PATCH] reduce upper legs dragging spine when single spine tracker --- gui/app/src/index.scss | 12 +++---- .../inputprocessors/rotation-smoothing.kt | 5 ++- .../slimevr/skeleton/inputprocessors/spine.kt | 31 ++++++++++++++----- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/gui/app/src/index.scss b/gui/app/src/index.scss index 99b96c492..f7d25cbac 100644 --- a/gui/app/src/index.scss +++ b/gui/app/src/index.scss @@ -123,12 +123,12 @@ body { :root[data-theme='space'] { --background-10: 255, 255, 255; - --background-20: 154, 149, 158; - --background-30: 129, 125, 133; - --background-40: 89, 86, 92; - --background-50: 54, 52, 56; - --background-60: 40, 38, 41; - --background-70: 25, 24, 26; + --background-20: 155, 150, 158; + --background-30: 129, 126, 133; + --background-40: 90, 87, 92; + --background-50: 55, 53, 56; + --background-60: 40, 39, 41; + --background-70: 25, 25, 26; --background-80: 10, 10, 10; --background-90: 4, 4, 4; diff --git a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/rotation-smoothing.kt b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/rotation-smoothing.kt index acfd80bf9..d08e94c45 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/rotation-smoothing.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/rotation-smoothing.kt @@ -13,8 +13,8 @@ import solarxr_protocol.rpc.FilteringType import solarxr_protocol.rpc.ResetType private const val SMOOTHING_MULTIPLIER = 100f -private const val SMOOTH_MIN = 0.5f -private const val SMOOTH_MAX = 0.95f +private const val SMOOTH_MIN = 0.46f +private const val SMOOTH_MAX = 0.92f /** * Running average of bone rotations to smooth them out. @@ -25,7 +25,6 @@ class RotationSmoothingInputProcessor(val settings: Settings) : private var smoothed: BodyPartMap = bodyPartMap() private var lastProcessTime = timeSource.markNow() - // TODO this isn't linear. Do we want linear smoothing like in main? override fun process(mutableInputSkeleton: InputSkeleton, skeletonHeight: Float) { val config = settings.context.state.value.data.skeletonConfig.filtering val filteringAmount = config.amount diff --git a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/spine.kt b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/spine.kt index d6eb05d89..a7e772606 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/spine.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/spine.kt @@ -9,6 +9,7 @@ import io.github.axisangles.ktmath.Quaternion import io.github.axisangles.ktmath.Vector3 import solarxr_protocol.datatypes.BodyPart import kotlin.enums.enumEntries +import kotlin.math.abs // At this default value, the user's spine should behave as we meant it to. const val DEFAULT_SPINE_UPPER_LOWER = 0.5f @@ -132,19 +133,33 @@ private fun buildFromTo(sourceActive: Map) = SPINE_SOURCE_ spineSource to (from to to) } -private fun averageRotation(inputSkeleton: InputSkeleton, takeBodyParts: Array = arrayOf()): Quaternion? { - val bonesToAverage = inputSkeleton.values.filter { it.bodyPart in takeBodyParts } - return bonesToAverage.map { it.rotation } - .reduceIndexedOrNull { index, acc, rotation -> - // Very important that this is interpQ as lerpQ will break on axes/polarity - acc.interpQ(rotation, 1f / (index + 1)) - } +// Higher value makes it so attitude is less prioritized +const val ATTITUDE_MIN = 0.3f +/** + * Prioritize the rotation with the lowest attitude to prevent one thigh driving the whole spine by itself. + * TODO to improve this even more for cases like crossing legs while sitting down, we need to use the rotation delta + * from the From. E.g: when using Upper Chest + Upper Legs, need to use delta from each Upper Leg to Upper Chest. + * This would allow us to apply different weights to forward (x-axis) rotation and side (z-axis rotation). + */ +private fun attitudeWeightedAverageRotation(inputSkeleton: InputSkeleton, bodyParts: Array = arrayOf()): Quaternion? { + val rotationsToAverage = inputSkeleton.values.filter { it.bodyPart in bodyParts }.map { it.rotation } + if (rotationsToAverage.count() <= 1) return rotationsToAverage.firstOrNull() + // TODO should SpineSource's parameter be a Pair with a nullable second argument? + if (rotationsToAverage.count() > 2) error("attitudeWeightedAverageRotation only works with 2 rotations max") + + val attitudeLengthSum = rotationsToAverage.sumOf { ATTITUDE_MIN + (it.eulerHeading().inv() * it).angleQ().toDouble() }.toFloat() + return rotationsToAverage + .fold(Quaternion.ZERO) { acc, rotation -> + // This only works for 2 rotations, but we don't have any case with >2 anyways + val ratio = abs(1 - ((ATTITUDE_MIN + (rotation.eulerHeading().inv() * rotation).angleQ()) / attitudeLengthSum)) + acc + (rotation * ratio) + }.unit() } private fun weightedAverageRotation(sources: List, reliabilities: Map, boneInputs: InputSkeleton): Quaternion { var accProportion = 0f return sources.foldIndexed(Quaternion.ZERO) { i, acc, fromSource -> - val rotation = averageRotation(boneInputs, fromSource.parts) + val rotation = attitudeWeightedAverageRotation(boneInputs, fromSource.parts) if (rotation != null) { val proportion = if (i + 1 == sources.count()) { // Use all the remaining