mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-12-06 08:42:32 -08:00
Improved neck tracking estimation
This commit is contained in:
1 parent
fc9666cc7f
commit
b8a4be7c36
5 files changed
+45
-7
No files matched your search
@@ -11,7 +11,6 @@ import solarxr_protocol.datatypes.BodyPart
|
||||
*/
|
||||
val BONE_DIRECT_LINK_SOURCES = arrayOf(
|
||||
BodyPart.HEAD to BodyPart.NECK,
|
||||
BodyPart.NECK to BodyPart.HEAD,
|
||||
|
||||
BodyPart.LEFT_FOOT to BodyPart.LEFT_LOWER_LEG,
|
||||
BodyPart.RIGHT_FOOT to BodyPart.RIGHT_LOWER_LEG,
|
||||
|
||||
+1
-2
@@ -1,6 +1,5 @@
|
||||
package dev.slimevr.skeleton.inputprocessors
|
||||
|
||||
import dev.slimevr.config.Settings
|
||||
import dev.slimevr.skeleton.InputSkeleton
|
||||
import dev.slimevr.skeleton.SkeletonInputProcessor
|
||||
import io.github.axisangles.ktmath.Vector3
|
||||
@@ -9,7 +8,7 @@ import solarxr_protocol.datatypes.BodyPart
|
||||
/**
|
||||
* Moves the head input to the skeleton height. Else, it would default to (0, 0, 0).
|
||||
*/
|
||||
class HeadPositionFallbackProcessor(val settings: Settings) : SkeletonInputProcessor {
|
||||
class HeadPositionFallbackInputProcessor : SkeletonInputProcessor {
|
||||
override fun process(mutableInputSkeleton: InputSkeleton, skeletonHeight: Float) {
|
||||
val headBone = mutableInputSkeleton[BodyPart.HEAD] ?: return
|
||||
if (headBone.position != null) return
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package dev.slimevr.skeleton.inputprocessors
|
||||
|
||||
import dev.slimevr.skeleton.InputSkeleton
|
||||
import dev.slimevr.skeleton.SkeletonInputProcessor
|
||||
import io.github.axisangles.ktmath.Vector3
|
||||
import solarxr_protocol.datatypes.BodyPart
|
||||
|
||||
private const val UP_RATIO = 0.9f
|
||||
private const val DOWN_RATIO = 1.1f
|
||||
|
||||
/**
|
||||
* Guesses where the neck is supposed to be when the user has a head tracker but no neck tracker.
|
||||
*
|
||||
* Tries to mitigate the problem where looking down make your whole tracking go down (or
|
||||
* knees bend if floorclip is enabled).
|
||||
*/
|
||||
class NeckInputProcessor : SkeletonInputProcessor {
|
||||
override fun process(mutableInputSkeleton: InputSkeleton, skeletonHeight: Float) {
|
||||
val headBone = mutableInputSkeleton[BodyPart.HEAD] ?: return
|
||||
val neckBone = mutableInputSkeleton[BodyPart.NECK] ?: return
|
||||
val upperChestBone = mutableInputSkeleton[BodyPart.UPPER_CHEST] ?: return
|
||||
if (!headBone.isRotationActive || neckBone.isRotationActive) return
|
||||
|
||||
// Work with the rotation delta to avoid axes being ambiguous
|
||||
val delta = upperChestBone.rotation.inv() * headBone.rotation
|
||||
|
||||
// Decompose the delta into its twist (forward) and swing (remaining/sides) along the x-axis
|
||||
val forward = delta.project(Vector3.POS_X).unit()
|
||||
val side = delta / forward
|
||||
|
||||
// Get the ratio depending on if the user is looking down or up
|
||||
val ratio = if (forward.x < 0f) DOWN_RATIO else UP_RATIO
|
||||
|
||||
val scaledDelta = side * forward.pow(ratio)
|
||||
val newRotation = upperChestBone.rotation * scaledDelta
|
||||
mutableInputSkeleton[BodyPart.NECK] = neckBone.copy(rotation = newRotation)
|
||||
}
|
||||
}
|
||||
@@ -147,7 +147,7 @@ private fun averageRotation(inputSkeleton: InputSkeleton, takeBodyParts: Array<B
|
||||
/**
|
||||
* Interpolates between 2 rotations with a different ratio for forward and the rest/side.
|
||||
*/
|
||||
private fun interpolateForwardSide(fromRotation: Quaternion, toRotation: Quaternion, forwardRatio: Float, sideRatio: Float?): Quaternion {
|
||||
fun interpolateForwardSide(fromRotation: Quaternion, toRotation: Quaternion, forwardRatio: Float, sideRatio: Float?): Quaternion {
|
||||
if (sideRatio == null) return fromRotation.interpQ(toRotation, forwardRatio)
|
||||
|
||||
// Work with the rotation delta to avoid axes being ambiguous
|
||||
|
||||
@@ -12,7 +12,8 @@ import dev.slimevr.skeleton.inputprocessors.ConstraintInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.DirectLinkInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.FallbackInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.FingersInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.HeadPositionFallbackProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.HeadPositionFallbackInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.NeckInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.RotationPredictionInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.RotationSmoothingInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.SpineInputProcessor
|
||||
@@ -277,10 +278,11 @@ class Skeleton(
|
||||
RotationPredictionInputProcessor(settings),
|
||||
RotationSmoothingInputProcessor(settings),
|
||||
TrackerOffsetInputProcessor(),
|
||||
HeadPositionFallbackProcessor(settings),
|
||||
HeadPositionFallbackInputProcessor(),
|
||||
FallbackInputProcessor(),
|
||||
SpineInputProcessor(settings),
|
||||
UpperLegsRollAlignInputProcessor(settings),
|
||||
SpineInputProcessor(settings),
|
||||
NeckInputProcessor(),
|
||||
DirectLinkInputProcessor(),
|
||||
FingersInputProcessor(),
|
||||
ToesInputProcessor(),
|
||||
|
||||
Reference in new issue
Block a user