From ecaabe5e6d68f3534ce7a310a3aa443658734fec Mon Sep 17 00:00:00 2001 From: Erimel Date: Wed, 30 Sep 2026 18:03:40 -0400 Subject: [PATCH] Fix tracking pause and improve yaw fallback --- .../java/dev/slimevr/skeleton/behaviours.kt | 8 ++--- .../inputprocessors/bone-yaw-fallback.kt | 31 ++++++++++++++----- .../main/java/dev/slimevr/skeleton/module.kt | 12 +++++-- .../main/java/dev/slimevr/skeleton/reducer.kt | 9 +++++- 4 files changed, 45 insertions(+), 15 deletions(-) diff --git a/server/core/src/main/java/dev/slimevr/skeleton/behaviours.kt b/server/core/src/main/java/dev/slimevr/skeleton/behaviours.kt index b1f2a93da..94b4366d7 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/behaviours.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/behaviours.kt @@ -179,6 +179,7 @@ private class TickTimings(private val hz: Int, private val window: Duration, pri class ComputedSkeletonBehaviour( val hz: Int, + val alwaysActiveInputProcessors: List = emptyList(), val inputProcessors: List = emptyList(), val fkComputedProcessors: List = emptyList(), val fkProcessors: List = emptyList(), @@ -251,14 +252,13 @@ class ComputedSkeletonBehaviour( receiver.context.dispatch(SkeletonActions.ProcessorResetsApplied(pendingResets.size)) } + val preProcessedBoneInputs = runInputProcessors(alwaysActiveInputProcessors, targetState.boneInputs, targetState.skeletonHeight) val boneInputs = if (targetState.pausedProcessedBoneInputs != null) { - // TODO improve pause tracking code, maybe using a processor // Use already-processed paused tracking data except for the head - val headBone = targetState.boneInputs[BodyPart.HEAD] - targetState.pausedProcessedBoneInputs.mutateCopy { it[BodyPart.HEAD] = headBone?.copy(position = if (headBone.isPositionActive) headBone.position else it[BodyPart.HEAD]?.position) } + targetState.pausedProcessedBoneInputs.mutateCopy { it[BodyPart.HEAD] = preProcessedBoneInputs[BodyPart.HEAD] } } else { // Run pre-FK processors - val processedInputs = runInputProcessors(inputProcessors, targetState.boneInputs, targetState.skeletonHeight) + val processedInputs = runInputProcessors(inputProcessors, preProcessedBoneInputs, targetState.skeletonHeight) if (targetState.paused) { // We just paused tracking and this is the last frame before we rely on paused bone inputs // The buffer keeps being written after this, so state gets a copy diff --git a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/bone-yaw-fallback.kt b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/bone-yaw-fallback.kt index 78fd27840..d9afd5b21 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/bone-yaw-fallback.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/bone-yaw-fallback.kt @@ -4,24 +4,39 @@ import dev.slimevr.skeleton.InputSkeleton import dev.slimevr.skeleton.SkeletonInputProcessor import dev.slimevr.skeleton.forEachBone import dev.slimevr.skeleton.iterateBodyPartHierarchy -import io.github.axisangles.ktmath.Vector3 +import solarxr_protocol.datatypes.BodyPart import kotlin.collections.set /** * Handles replacing rotations of boneInputs that are not actively receiving data by - * falling back to their parent's yaw. + * falling back to their parent's, then children's, yaw. */ class BoneYawFallbackInputProcessor : SkeletonInputProcessor { override fun process(mutableInputSkeleton: InputSkeleton, skeletonHeight: Float) { + val processedParts: MutableList = mutableListOf() mutableInputSkeleton.forEachBone { parentPart, parentBone -> - if (!parentBone.isRotationActive) return@forEachBone // Parent needs to be active + if (!parentBone.isRotationActive) { + if (parentPart in processedParts) return@forEachBone - val parentYaw = parentBone.rotation.eulerHeading() - for (childPart in iterateBodyPartHierarchy(parentPart, true)) { - val childBone = mutableInputSkeleton[childPart.second] ?: continue - if (childBone.isRotationActive) continue // Child needs to be inactive + // Parent doesn't have rotation and didn't get any earlier in the chain. + // Use this parent's children to set its own yaw. + val childYaw = iterateBodyPartHierarchy(parentPart, true).firstOrNull { (_, childPart) -> + mutableInputSkeleton[childPart]?.isRotationActive ?: false + }?.let { (_, childPart) -> + mutableInputSkeleton[childPart]?.rotation?.eulerHeading() ?: return@forEachBone + } ?: return@forEachBone - mutableInputSkeleton[childPart.second] = childBone.copy(rotation = parentYaw) + mutableInputSkeleton[parentPart] = parentBone.copy(rotation = childYaw) + } else { + // Use this parent's yaw to set the children's yaw. + val parentYaw = parentBone.rotation.eulerHeading() + for ((_, childPart) in iterateBodyPartHierarchy(parentPart, true)) { + val childBone = mutableInputSkeleton[childPart] ?: continue + if (childBone.isRotationActive) continue // Child needs to be inactive + + processedParts.add(childPart) + mutableInputSkeleton[childPart] = childBone.copy(rotation = parentYaw) + } } } } 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 7a402ee91..64e1ac788 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/module.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/module.kt @@ -269,11 +269,15 @@ class Skeleton( ComputedSkeletonBehaviour( hz = hz, waiter = waiter, - inputProcessors = listOf( - TrackerOffsetInputProcessor(), + // Like inputProcessors but run even when tracking is paused (since head isn't paused) + alwaysActiveInputProcessors = listOf( PredictionInputProcessor(settings), SmoothingInputProcessor(settings), + TrackerOffsetInputProcessor(), HeadPositionFallbackProcessor(settings), + ), + // Run before FK on the inputs + inputProcessors = listOf( BoneYawFallbackInputProcessor(), SpineInputProcessor(settings), HipYawRollAlignInputProcessor(settings), @@ -284,19 +288,23 @@ class Skeleton( ConstraintInputProcessor(settings), AccelerationFallbackInputProcessor(), ), + // Run on the result of FK and persist fkComputedProcessors = listOf( VelocityComputedProcessor(), ), + // Run on the inputs with the result of FK and run FK fkProcessors = listOf( LocalizerFkProcessor(settings), FootPlantFkProcessor(skeleton), ToeSnapFkProcessor(skeleton), ), + // Create targets for IK targetProcessors = listOf( PositionalTargetProcessor(settings), SkatingCorrectionTargetProcessor(settings, skeleton), FloorClipTargetProcessor(skeleton), ), + // Run on the result of IK and persist. ikComputedProcessors = listOf( VelocityComputedProcessor(), ), diff --git a/server/core/src/main/java/dev/slimevr/skeleton/reducer.kt b/server/core/src/main/java/dev/slimevr/skeleton/reducer.kt index 333e2fbf8..da190d2b0 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/reducer.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/reducer.kt @@ -54,7 +54,14 @@ fun reduce(state: SkeletonState, action: SkeletonActions): SkeletonState = when is SkeletonActions.PauseTracking -> state.copy(paused = action.pause, pausedProcessedBoneInputs = null) - is SkeletonActions.SetPausedBoneInputs -> state.copy(pausedProcessedBoneInputs = action.pausedBoneInputs) + is SkeletonActions.SetPausedBoneInputs -> state.copy( + pausedProcessedBoneInputs = action.pausedBoneInputs.mutateCopy { + action.pausedBoneInputs.forEach { (part, input) -> + // Remove acceleration from paused inputs but the active flag as it was. + it[part] = input.copy(acceleration = Vector3.ZERO) + } + }, + ) is SkeletonActions.ResetHeadPosition -> { val headBone = state.boneInputs[BodyPart.HEAD] ?: return state