Fix tracking pause and improve yaw fallback

This commit is contained in:
Erimel committed 2026-09-30 18:03:40 -04:00
1 parent f58c4dc24f
commit ecaabe5e6d
4 files changed
+45 -15

No files matched your search

@@ -179,6 +179,7 @@ private class TickTimings(private val hz: Int, private val window: Duration, pri
class ComputedSkeletonBehaviour(
val hz: Int,
val alwaysActiveInputProcessors: List<SkeletonInputProcessor> = emptyList(),
val inputProcessors: List<SkeletonInputProcessor> = emptyList(),
val fkComputedProcessors: List<SkeletonComputedProcessor> = emptyList(),
val fkProcessors: List<SkeletonFkProcessor> = 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
@@ -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<BodyPart> = 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)
}
}
}
}
@@ -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(),
),
@@ -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