mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-21 01:21:25 -08:00
Send resetType on resetProcessors
This commit is contained in:
1 parent
aaf392c21c
commit
f7db29fb2c
7 files changed
+45
-24
No files matched your search
@@ -91,11 +91,11 @@ class ResetsManager(val context: ResetsContext, val server: VRServer, val settin
|
||||
if (resetType == ResetType.FULL) {
|
||||
// Tell the skeleton to set the floor level and try resetting the head position (for mocap mode)
|
||||
skeleton.context.dispatchAll(listOf(SkeletonActions.ResetHeadPosition, SkeletonActions.ComputeFloorLevel))
|
||||
|
||||
// Reset the skeleton processors that keep data not in states (smoothing, localizer, skating correction, etc.)
|
||||
skeleton.resetProcessors()
|
||||
}
|
||||
|
||||
// Reset the skeleton processors that store temporary data (smoothing, localizer, skating correction, etc.)
|
||||
skeleton.resetProcessors(resetType)
|
||||
|
||||
// Update state and config
|
||||
context.dispatch(ResetsActions.EndReset(resetType, bodyParts, settings.context.state.value.data.resetsConfig.resetMountingFeet))
|
||||
settings.context.dispatch(
|
||||
|
||||
@@ -2,6 +2,7 @@ package dev.slimevr.skeleton.computedprocessors
|
||||
|
||||
import dev.slimevr.skeleton.BodyPartMap
|
||||
import dev.slimevr.skeleton.ComputedSkeleton
|
||||
import dev.slimevr.skeleton.ResettableSkeletonProcessor
|
||||
import dev.slimevr.skeleton.SkeletonComputedProcessor
|
||||
import dev.slimevr.skeleton.Velocity
|
||||
import dev.slimevr.skeleton.ZERO_VELOCITY
|
||||
@@ -12,6 +13,7 @@ import dev.slimevr.util.timeSource
|
||||
import io.github.axisangles.ktmath.Quaternion
|
||||
import io.github.axisangles.ktmath.Vector3
|
||||
import solarxr_protocol.datatypes.BodyPart
|
||||
import solarxr_protocol.rpc.ResetType
|
||||
import kotlin.time.Duration.Companion.milliseconds
|
||||
|
||||
private data class VelocityBoneData(
|
||||
@@ -42,7 +44,9 @@ private fun smoothVelocity(currentVelocity: Velocity, lastVelocity: Velocity, de
|
||||
/**
|
||||
* Computes linear (m/s) and angular (rad/s) velocity for the bones.
|
||||
*/
|
||||
class VelocityComputedProcessor : SkeletonComputedProcessor {
|
||||
class VelocityComputedProcessor :
|
||||
SkeletonComputedProcessor,
|
||||
ResettableSkeletonProcessor {
|
||||
private val lastVelocities: BodyPartMap<Velocity> = bodyPartMap()
|
||||
private val lastVelocityBoneData: BodyPartMap<VelocityBoneData> = bodyPartMap()
|
||||
private var lastProcessTime = timeSource.markNow()
|
||||
@@ -69,4 +73,9 @@ class VelocityComputedProcessor : SkeletonComputedProcessor {
|
||||
lastVelocities[part] = newVelocity
|
||||
}
|
||||
}
|
||||
|
||||
override fun reset(resetType: ResetType) {
|
||||
lastVelocities.clear()
|
||||
lastVelocityBoneData.clear()
|
||||
}
|
||||
}
|
||||
@@ -241,11 +241,13 @@ class LocalizerFkProcessor(val settings: Settings) :
|
||||
mutableInputSkeleton[BodyPart.HEAD] = headInput.copy(position = newHeadPosition)
|
||||
}
|
||||
|
||||
override fun reset() {
|
||||
targetFoot = Vector3.ZERO
|
||||
sittingTime = Duration.ZERO
|
||||
targetHip = Vector3.ZERO
|
||||
comVelocity = Vector3.ZERO
|
||||
targetCOM = Vector3.ZERO
|
||||
override fun reset(resetType: ResetType) {
|
||||
if (resetType == ResetType.FULL) {
|
||||
targetFoot = Vector3.ZERO
|
||||
sittingTime = Duration.ZERO
|
||||
targetHip = Vector3.ZERO
|
||||
comVelocity = Vector3.ZERO
|
||||
targetCOM = Vector3.ZERO
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package dev.slimevr.skeleton.inputprocessors
|
||||
import dev.slimevr.config.Settings
|
||||
import dev.slimevr.skeleton.BodyPartMap
|
||||
import dev.slimevr.skeleton.InputSkeleton
|
||||
import dev.slimevr.skeleton.ResettableSkeletonProcessor
|
||||
import dev.slimevr.skeleton.SkeletonInputProcessor
|
||||
import dev.slimevr.skeleton.bodyPartMap
|
||||
import dev.slimevr.skeleton.forEachBone
|
||||
@@ -11,6 +12,7 @@ import dev.slimevr.util.timeSource
|
||||
import io.github.axisangles.ktmath.Quaternion
|
||||
import solarxr_protocol.datatypes.BodyPart
|
||||
import solarxr_protocol.rpc.FilteringType
|
||||
import solarxr_protocol.rpc.ResetType
|
||||
import kotlin.time.Duration.Companion.milliseconds
|
||||
|
||||
/** How far ahead the prediction reaches at amount 1, scaled down by the configured amount */
|
||||
@@ -19,7 +21,9 @@ val PREDICTION_LEAD = 10.milliseconds
|
||||
/**
|
||||
* Tries to predict future rotations of bones.
|
||||
*/
|
||||
class BonePredictionInputProcessor(val settings: Settings) : SkeletonInputProcessor {
|
||||
class BonePredictionInputProcessor(val settings: Settings) :
|
||||
SkeletonInputProcessor,
|
||||
ResettableSkeletonProcessor {
|
||||
private data class BoneVelocity(
|
||||
val lastRotation: Quaternion,
|
||||
val rotationDelta: Quaternion,
|
||||
@@ -77,4 +81,8 @@ class BonePredictionInputProcessor(val settings: Settings) : SkeletonInputProces
|
||||
}
|
||||
velocities = newVelocities
|
||||
}
|
||||
|
||||
override fun reset(resetType: ResetType) {
|
||||
velocities.clear()
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import solarxr_protocol.rpc.FilteringType
|
||||
import solarxr_protocol.rpc.ResetType
|
||||
|
||||
private const val SMOOTHING_MULTIPLIER = 100f
|
||||
private const val SMOOTH_MIN = 0.54f
|
||||
private const val SMOOTH_MIN = 0.52f
|
||||
private const val SMOOTH_MAX = 0.95f
|
||||
|
||||
/**
|
||||
@@ -56,7 +56,7 @@ class BoneSmoothingInputProcessor(val settings: Settings) :
|
||||
smoothed = newSmoothed
|
||||
}
|
||||
|
||||
override fun reset() {
|
||||
override fun reset(resetType: ResetType) {
|
||||
smoothed.clear()
|
||||
}
|
||||
}
|
||||
@@ -164,7 +164,7 @@ typealias SkeletonContext = Context<SkeletonState, SkeletonActions>
|
||||
typealias SkeletonBehaviour = Behaviour<Skeleton>
|
||||
|
||||
interface ResettableSkeletonProcessor {
|
||||
fun reset()
|
||||
fun reset(resetType: ResetType)
|
||||
}
|
||||
interface SkeletonInputProcessor {
|
||||
fun process(mutableInputSkeleton: InputSkeleton, skeletonHeight: Float)
|
||||
@@ -189,8 +189,8 @@ class Skeleton(
|
||||
|
||||
fun startObserving() = context.observeAll(this)
|
||||
|
||||
fun resetProcessors() {
|
||||
resettableSkeletonProcessors.forEach { it.reset() }
|
||||
fun resetProcessors(resetType: ResetType) {
|
||||
resettableSkeletonProcessors.forEach { it.reset(resetType) }
|
||||
}
|
||||
|
||||
companion object {
|
||||
@@ -209,7 +209,7 @@ class Skeleton(
|
||||
hz = hz,
|
||||
waiter = waiter,
|
||||
inputProcessors = listOf(
|
||||
BonePredictionInputProcessor(settings),
|
||||
BonePredictionInputProcessor(settings).also { resettableSkeletonProcessors.add(it) },
|
||||
BoneSmoothingInputProcessor(settings).also { resettableSkeletonProcessors.add(it) },
|
||||
HeadPositionFallbackProcessor(settings),
|
||||
BoneYawFallbackInputProcessor(),
|
||||
@@ -221,7 +221,7 @@ class Skeleton(
|
||||
FingerImputeInputProcessor(),
|
||||
),
|
||||
fkComputedProcessors = listOf(
|
||||
VelocityComputedProcessor(),
|
||||
VelocityComputedProcessor().also { resettableSkeletonProcessors.add(it) },
|
||||
),
|
||||
fkProcessors = listOf(
|
||||
LocalizerFkProcessor(settings).also { resettableSkeletonProcessors.add(it) },
|
||||
@@ -230,10 +230,10 @@ class Skeleton(
|
||||
),
|
||||
targetProcessors = listOf(
|
||||
// FloorClipTargetProcessor(settings),
|
||||
// SkatingCorrectionTargetProcessor(settings).also { resettableSkeletonProcessors.add(it) },
|
||||
SkatingCorrectionTargetProcessor(settings).also { resettableSkeletonProcessors.add(it) },
|
||||
),
|
||||
ikComputedProcessors = listOf(
|
||||
VelocityComputedProcessor(),
|
||||
VelocityComputedProcessor().also { resettableSkeletonProcessors.add(it) },
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
+6
-4
@@ -129,9 +129,11 @@ class SkatingCorrectionTargetProcessor(val settings: Settings) :
|
||||
}
|
||||
}
|
||||
|
||||
override fun reset() {
|
||||
comState = null
|
||||
lastLockedPositions.clear()
|
||||
lockState.clear()
|
||||
override fun reset(resetType: ResetType) {
|
||||
if (resetType == ResetType.FULL) {
|
||||
comState = null
|
||||
lastLockedPositions.clear()
|
||||
lockState.clear()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user