Compare commits

...
Author SHA1 Message Date
Erimel 476d81584d 25ms PREDICTION_CARRYOVER_TIME 2026-11-30 17:06:05 +01:00
Erimel 9937b42c46 skating correction stronger when no feet 2026-11-30 16:57:26 +01:00
Erimel a0f6bbfd92 PacketDropSimulatorInputProcessor 2026-11-30 16:50:35 +01:00
6 changed files with 49 additions and 4 deletions

No files matched your search

@@ -117,7 +117,7 @@ data class SkeletonTogglesConfig(
@Serializable
data class SkeletonRatiosConfig(
val smoothingStrength: Float = 0.15f,
val predictionStrength: Float = 0.30f,
val predictionStrength: Float = 0.25f,
val spineCurvature: Float = 0.75f,
val imputeSpineFromUpperToLower: Float = DEFAULT_SPINE_UPPER_LOWER,
val interpolateUpperLegsTwistWithLowerLegs: Float = 0.85f,
@@ -75,6 +75,8 @@ class LocalizerResetBehaviour(val settings: Settings) : SkeletonBehaviour {
*/
class YouSpinMeRightRoundBehaviour(val inputHz: Int = 100, val speed: Float = 1f, val randomPacketLoss: Float = 0f, val constantPacketLoss: Float = 0f, val sendPosition: Boolean = false) : SkeletonBehaviour {
override fun observe(receiver: Skeleton) {
println("YouSpinMeRightRoundBehaviour sending fake bone data for simulation.")
receiver.context.scope.launch {
val interval = (millisecondsInSecond / inputHz.toFloat()).toLong().milliseconds
val startTime = timeSource.markNow()
@@ -36,7 +36,7 @@ private const val SMOOTHING_MS_MAX = 50.0
// Prediction
private const val PREDICTION_MS_MAX = 30.0
private val PREDICTION_CARRYOVER_TIME = 20.milliseconds // TODO might need to be tuned
private val PREDICTION_CARRYOVER_TIME = 25.milliseconds
private const val MAX_PREDICTION_CARRYOVER_RATIO = 0.5
// Used to minimize latency even more for arm tracking where it is more noticeable
@@ -0,0 +1,37 @@
package dev.slimevr.skeleton.inputprocessors
import dev.slimevr.skeleton.BodyPartMap
import dev.slimevr.skeleton.BoneInput
import dev.slimevr.skeleton.InputSkeleton
import dev.slimevr.skeleton.SkeletonInputProcessor
import dev.slimevr.skeleton.bodyPartMap
import kotlin.random.Random
import kotlin.time.ComparableTimeMark
/**
* Used for simulating packet drop, leave commented for production.
*/
class PacketDropSimulatorInputProcessor(val randomPacketDrop: Float) : SkeletonInputProcessor {
init {
println("PacketDropSimulatorInputProcessor simulating ${randomPacketDrop * 100}% packet drop.")
}
val lastBone: BodyPartMap<BoneInput> = bodyPartMap()
val lastPoseTime: BodyPartMap<ComparableTimeMark> = bodyPartMap()
override fun process(mutableInputSkeleton: InputSkeleton, skeletonHeight: Float) {
mutableInputSkeleton.forEach { (part, input) ->
val isNewData = lastPoseTime[part] != mutableInputSkeleton[part]?.poseTime
lastPoseTime[part] = mutableInputSkeleton[part]?.poseTime
if (isNewData) {
val dropPacket = Random.nextFloat() < randomPacketDrop
if (!dropPacket) {
lastBone[part] = input
} else if (lastBone[part] != null) {
mutableInputSkeleton[part] = lastBone[part]
}
} else if (lastBone[part] != null) {
mutableInputSkeleton[part] = lastBone[part]
}
}
}
}
@@ -17,6 +17,7 @@ import dev.slimevr.skeleton.inputprocessors.FilteringInputProcessor
import dev.slimevr.skeleton.inputprocessors.FingersInputProcessor
import dev.slimevr.skeleton.inputprocessors.HeadPositionFallbackInputProcessor
import dev.slimevr.skeleton.inputprocessors.NeckInputProcessor
import dev.slimevr.skeleton.inputprocessors.PacketDropSimulatorInputProcessor
import dev.slimevr.skeleton.inputprocessors.SpineInputProcessor
import dev.slimevr.skeleton.inputprocessors.ToesInputProcessor
import dev.slimevr.skeleton.targetprocessors.FloorClipTargetProcessor
@@ -262,12 +263,13 @@ class Skeleton(
ProportionsBehaviour(ctx.config.userConfig),
HeightLogBehaviour(),
LocalizerResetBehaviour(settings),
// YouSpinMeRightRoundBehaviour(inputHz = 100, speed = 1f, randomPacketLoss = 0f, constantPacketLoss = 0f, sendPosition = true),
// YouSpinMeRightRoundBehaviour(inputHz = 100, speed = 1f, randomPacketLoss = 0.9f, constantPacketLoss = 0f, sendPosition = false),
ComputedSkeletonBehaviour(
hz = hz,
waiter = waiter,
// Run before FK on the inputs
inputProcessors = listOf(
// PacketDropSimulatorInputProcessor(0.85f),
FilteringInputProcessor(settings),
HeadPositionFallbackInputProcessor(),
FallbackInputProcessor(),
@@ -27,6 +27,7 @@ const val OFFSET_LIMIT_MAX = 0.20f
const val COM_DISTANCE_MULTIPLIER = 1.5f
const val LIFT_MIN = -0.85f
const val LIFT_MAX = 0.4f
const val ANKLE_MULTIPLIER = 1.25f
// Parameters to decide if a foot should be locked
// Higher makes it harder to unlock after being locked
@@ -226,6 +227,7 @@ class SkatingCorrectionTargetProcessor(val settings: Settings, val skeleton: Ske
for ((bodyPart, ikTargetBodyPart, liftBodyPart) in skatingBodyParts) {
val bone = fk[bodyPart] ?: continue
val inputBone = inputSkeleton[bodyPart] ?: continue
val ikBone = fk[ikTargetBodyPart] ?: continue
val liftBone = fk[liftBodyPart] ?: continue
val curPosition = mutableIkTargets[ikTargetBodyPart] ?: ikBone.tailPosition
@@ -235,8 +237,10 @@ class SkatingCorrectionTargetProcessor(val settings: Settings, val skeleton: Ske
val comMultiplier = computeComMultiplier(comDistances[bodyPart] ?: continue, comDistancesAverage)
// liftMultiplier decreases the threshold when the upper leg is lifted. Useful when sitting/lying down
val liftMultiplier = computeLiftMultiplier(liftBone.localTailPosition)
// ankleMultiplier increases the threshold if the foot doesn't have its own accel data
val ankleMultiplier = if (inputBone.isAccelerationActive) 1f else ANKLE_MULTIPLIER
// Apply multipliers to the acceleration threshold
val scaledAccelerationThreshold = accelerationThreshold * comMultiplier * liftMultiplier
val scaledAccelerationThreshold = accelerationThreshold * comMultiplier * liftMultiplier * ankleMultiplier
// Compute if the body part should be locked
val floorLocked = floorLocked(lastState.locked, curPosition, floorLevel)