mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-12-06 08:42:32 -08:00
No more hip-upperlegs interpolation; improve chest-only tracking
This commit is contained in:
1 parent
efac8fda65
commit
7d72dc2c8a
14 files changed
+29
-102
No files matched your search
@@ -157,8 +157,7 @@ class AppConfig(
|
||||
ProfileKind.UNKNOWN -> error("No active profile for $kind")
|
||||
}
|
||||
|
||||
private suspend fun listProfiles(kind: ProfileKind): List<String> =
|
||||
(profileNamesIn(storage.list(dirOf(kind))) + activeProfile(kind)).distinct().sortedBy { it.lowercase() }
|
||||
private suspend fun listProfiles(kind: ProfileKind): List<String> = (profileNamesIn(storage.list(dirOf(kind))) + activeProfile(kind)).distinct().sortedBy { it.lowercase() }
|
||||
|
||||
private suspend fun profileOperation(kind: ProfileKind, block: suspend () -> ProfileOperationStatus): ProfileOperationStatus = profilesLock.withLock {
|
||||
if (kind == ProfileKind.UNKNOWN) return@withLock ProfileOperationStatus.INVALID_KIND
|
||||
@@ -275,8 +274,7 @@ class AppConfig(
|
||||
}
|
||||
|
||||
// A profile named like the default in another case is the same file on case-insensitive filesystems
|
||||
private suspend fun defaultProfileName(kind: ProfileKind, name: String): String =
|
||||
listProfiles(kind).firstOrNull { it.equals(name, ignoreCase = true) } ?: name
|
||||
private suspend fun defaultProfileName(kind: ProfileKind, name: String): String = listProfiles(kind).firstOrNull { it.equals(name, ignoreCase = true) } ?: name
|
||||
|
||||
companion object {
|
||||
suspend fun create(scope: CoroutineScope, storage: ConfigStorage): AppConfig {
|
||||
|
||||
@@ -137,9 +137,8 @@ data class SkeletonTogglesConfig(
|
||||
// Used in SkeletonConfig
|
||||
@Serializable
|
||||
data class SkeletonRatiosConfig(
|
||||
val imputeSpineFromUpperToLower: Float = DEFAULT_SPINE_UPPER_LOWER,
|
||||
val spineCurvature: Float = 0.75f,
|
||||
val interpolateHipWithUpperLegs: Float = 0.25f,
|
||||
val imputeSpineFromUpperToLower: Float = DEFAULT_SPINE_UPPER_LOWER,
|
||||
val interpolateUpperLegsTwistWithLowerLegs: Float = 0.85f,
|
||||
val skatingCorrectionStrength: Float = 0.5f,
|
||||
)
|
||||
|
||||
@@ -3,6 +3,5 @@ package dev.slimevr.config
|
||||
fun reduce(state: UserConfigState, action: UserConfigActions): UserConfigState = when (action) {
|
||||
is UserConfigActions.Update -> state.copy(data = action.transform(state.data))
|
||||
is UserConfigActions.LoadProfile -> action.newState
|
||||
|
||||
is UserConfigActions.Rename -> state.copy(name = action.name)
|
||||
}
|
||||
@@ -5,9 +5,9 @@ import dev.slimevr.config.SettingsActions
|
||||
import dev.slimevr.hid.HIDReceiver
|
||||
import dev.slimevr.hid.HIDReceiverActions
|
||||
import dev.slimevr.hid.HIDReceiverBehaviour
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.distinctUntilChangedBy
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
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.Quaternion
|
||||
import solarxr_protocol.datatypes.BodyPart
|
||||
|
||||
/**
|
||||
* Rotates the first Quaternion to match its yaw and roll to the rotation of
|
||||
* the second Quaternion
|
||||
*
|
||||
* @param from the first Quaternion
|
||||
* @param to the second Quaternion
|
||||
* @return the rotated Quaternion
|
||||
*/
|
||||
private fun alignYawRoll(from: Quaternion, to: Quaternion): Quaternion {
|
||||
val r = from.inv() * to
|
||||
val c = Quaternion(r.w, -r.x, 0f, 0f)
|
||||
return (from * r * c).unit()
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles rotating the hip' yaw and roll to match the upper legs' yaw and roll.
|
||||
*/
|
||||
class HipYawRollAlignInputProcessor(val settings: Settings) : SkeletonInputProcessor {
|
||||
override fun process(mutableInputSkeleton: InputSkeleton, skeletonHeight: Float) {
|
||||
val hipBone = mutableInputSkeleton[BodyPart.HIP] ?: return
|
||||
if (hipBone.isRotationActive) return
|
||||
val leftUpperLegBone = mutableInputSkeleton[BodyPart.LEFT_UPPER_LEG] ?: return
|
||||
val rightUpperLegBone = mutableInputSkeleton[BodyPart.RIGHT_UPPER_LEG] ?: return
|
||||
if (!leftUpperLegBone.isRotationActive || !rightUpperLegBone.isRotationActive) return
|
||||
|
||||
val ratio = settings.context.state.value.data.skeletonConfig.ratios.interpolateHipWithUpperLegs
|
||||
val sourceRotation = leftUpperLegBone.rotation.lerpQ(rightUpperLegBone.rotation, 0.5f)
|
||||
val alignedRotation = alignYawRoll(hipBone.rotation, sourceRotation)
|
||||
mutableInputSkeleton[BodyPart.HIP] = hipBone.copy(rotation = hipBone.rotation.interpQ(alignedRotation, ratio))
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,6 @@ private val SPINE_SOURCES = enumEntries<SpineSource>().toTypedArray()
|
||||
// If a "To" is the same as "From", it'll do 50-50.
|
||||
// A negative value will go towards the opposite rotation.
|
||||
// A From and To may be taken from different roots.
|
||||
// TODO: Fine tune
|
||||
private val SPINE_SOURCE_RELIABILITY = arrayOf(
|
||||
SpineSource.UPPER_CHEST to mapOf(
|
||||
SpineSource.UPPER_CHEST to Reliability(-6.5f, -24f), // Itself
|
||||
@@ -43,7 +42,7 @@ private val SPINE_SOURCE_RELIABILITY = arrayOf(
|
||||
SpineSource.UPPER_WAIST to Reliability(1.5f),
|
||||
SpineSource.LOWER_WAIST to Reliability(2f),
|
||||
SpineSource.HIP to Reliability(4f),
|
||||
SpineSource.UPPER_LEGS to Reliability(2.5f),
|
||||
SpineSource.UPPER_LEGS to Reliability(1.5f, 1.75f),
|
||||
),
|
||||
SpineSource.LOWER_CHEST to mapOf(
|
||||
// From
|
||||
@@ -53,7 +52,7 @@ private val SPINE_SOURCE_RELIABILITY = arrayOf(
|
||||
SpineSource.UPPER_WAIST to Reliability(1.5f, 10f),
|
||||
SpineSource.LOWER_WAIST to Reliability(2f, 7f),
|
||||
SpineSource.HIP to Reliability(4f),
|
||||
SpineSource.UPPER_LEGS to Reliability(2.5f),
|
||||
SpineSource.UPPER_LEGS to Reliability(3.25f, 3.75f),
|
||||
),
|
||||
SpineSource.UPPER_WAIST to mapOf(
|
||||
// From
|
||||
@@ -63,7 +62,7 @@ private val SPINE_SOURCE_RELIABILITY = arrayOf(
|
||||
// To
|
||||
SpineSource.LOWER_WAIST to Reliability(17f, 20f),
|
||||
SpineSource.HIP to Reliability(5.5f, 5.5f),
|
||||
SpineSource.UPPER_LEGS to Reliability(3f, 2.5f),
|
||||
SpineSource.UPPER_LEGS to Reliability(0.25f, 2.5f),
|
||||
),
|
||||
SpineSource.LOWER_WAIST to mapOf(
|
||||
// From
|
||||
@@ -72,8 +71,8 @@ private val SPINE_SOURCE_RELIABILITY = arrayOf(
|
||||
SpineSource.UPPER_WAIST to Reliability(9f),
|
||||
SpineSource.LOWER_WAIST to Reliability(44f), // Itself
|
||||
// To
|
||||
SpineSource.HIP to Reliability(10f, 6.5f),
|
||||
SpineSource.UPPER_LEGS to Reliability(3.5f, 2.75f),
|
||||
SpineSource.HIP to Reliability(10f, 9f),
|
||||
SpineSource.UPPER_LEGS to Reliability(1.75f, 6f),
|
||||
),
|
||||
SpineSource.HIP to mapOf(
|
||||
// From
|
||||
@@ -81,9 +80,9 @@ private val SPINE_SOURCE_RELIABILITY = arrayOf(
|
||||
SpineSource.LOWER_CHEST to Reliability(9.5f),
|
||||
SpineSource.UPPER_WAIST to Reliability(13f, 14f),
|
||||
SpineSource.LOWER_WAIST to Reliability(14f, 15f),
|
||||
SpineSource.HIP to Reliability(35f), // Itself
|
||||
SpineSource.HIP to Reliability(32f, 48f), // Itself
|
||||
// To
|
||||
SpineSource.UPPER_LEGS to Reliability(12f, 10f),
|
||||
SpineSource.UPPER_LEGS to Reliability(7f, 18f),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ 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.HipYawRollAlignInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.RotationPredictionInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.RotationSmoothingInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.SpineInputProcessor
|
||||
@@ -276,7 +275,6 @@ class Skeleton(
|
||||
HeadPositionFallbackProcessor(settings),
|
||||
FallbackInputProcessor(),
|
||||
SpineInputProcessor(settings),
|
||||
HipYawRollAlignInputProcessor(settings),
|
||||
UpperLegsRollAlignInputProcessor(settings),
|
||||
DirectLinkInputProcessor(),
|
||||
FingersInputProcessor(),
|
||||
|
||||
@@ -37,9 +37,8 @@ internal fun buildSkeletonSettingsResponse(config: SkeletonConfig) = SkeletonSet
|
||||
enforceConstraints = config.toggles.enforceConstraints,
|
||||
),
|
||||
ratios = SkeletonRatios(
|
||||
imputeSpineFromUpperToLower = config.ratios.imputeSpineFromUpperToLower,
|
||||
spineCurvature = config.ratios.spineCurvature,
|
||||
interpolateHipWithUpperLegs = config.ratios.interpolateHipWithUpperLegs,
|
||||
imputeSpineFromUpperToLower = config.ratios.imputeSpineFromUpperToLower,
|
||||
interpolateUpperLegsTwistWithLowerLegs = config.ratios.interpolateUpperLegsTwistWithLowerLegs,
|
||||
skatingCorrectionStrength = config.ratios.skatingCorrectionStrength,
|
||||
),
|
||||
@@ -85,9 +84,8 @@ class SkeletonSettingsBehaviour(
|
||||
} ?: skeletonConfig.toggles,
|
||||
ratios = req.ratios?.let {
|
||||
SkeletonRatiosConfig(
|
||||
imputeSpineFromUpperToLower = it.imputeSpineFromUpperToLower ?: 0f,
|
||||
spineCurvature = it.spineCurvature ?: 0f,
|
||||
interpolateHipWithUpperLegs = it.interpolateHipWithUpperLegs ?: 0f,
|
||||
imputeSpineFromUpperToLower = it.imputeSpineFromUpperToLower ?: 0f,
|
||||
interpolateUpperLegsTwistWithLowerLegs = it.interpolateUpperLegsTwistWithLowerLegs ?: 0f,
|
||||
skatingCorrectionStrength = it.skatingCorrectionStrength ?: 0f,
|
||||
)
|
||||
|
||||
@@ -44,6 +44,8 @@ class TapDetectionBasicBehaviour : TapDetectionBehaviour {
|
||||
BodyPart.RIGHT_UPPER_LEG,
|
||||
BodyPart.LEFT_LOWER_LEG,
|
||||
BodyPart.RIGHT_LOWER_LEG,
|
||||
BodyPart.LEFT_FOOT,
|
||||
BodyPart.RIGHT_FOOT,
|
||||
)
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
@@ -208,8 +210,6 @@ class TapDetectionBasicBehaviour : TapDetectionBehaviour {
|
||||
trackerAcceleration: Vector3,
|
||||
thresholdMultiplier: Float,
|
||||
): Boolean {
|
||||
// TODO check logic against main since taps seem harder to trigger
|
||||
|
||||
// Remove old stored accelerations (if they are too old)
|
||||
while (trackerTapDetectionState.accelList.isNotEmpty() && (trackerTapDetectionState.accelList.first().second + ACCEL_WINDOW).hasPassedNow()) {
|
||||
trackerTapDetectionState.accelList.removeFirst()
|
||||
@@ -254,7 +254,7 @@ class TapDetectionBasicBehaviour : TapDetectionBehaviour {
|
||||
const val NEEDED_ACCEL_DELTA = 6.0f
|
||||
const val ALLOWED_BODY_ACCEL = 2.5f
|
||||
const val ALLOWED_BODY_ACCEL_SQUARED = ALLOWED_BODY_ACCEL * ALLOWED_BODY_ACCEL
|
||||
const val HID_MULTIPLIER = 1.2f
|
||||
const val HID_MULTIPLIER = 1.25f
|
||||
val ACCEL_WINDOW = 0.06.seconds
|
||||
val TAP_WINDOW_PER_TAP = 0.3.seconds
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user