mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-27 12:26:33 -08:00
reduce upper legs dragging spine when single spine tracker
This commit is contained in:
1 parent
e02cba43a2
commit
714f8cbca4
3 files changed
+31
-17
No files matched your search
@@ -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;
|
||||
|
||||
|
||||
+2
-3
@@ -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<Quaternion> = 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
|
||||
|
||||
@@ -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<SpineSource, Boolean>) = SPINE_SOURCE_
|
||||
spineSource to (from to to)
|
||||
}
|
||||
|
||||
private fun averageRotation(inputSkeleton: InputSkeleton, takeBodyParts: Array<BodyPart> = 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<BodyPart> = 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<SpineSource>, reliabilities: Map<SpineSource, Reliability>, 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
|
||||
|
||||
Reference in new issue
Block a user