Add acceleration and velocity to bones

This commit is contained in:
Erimel committed 2026-09-01 20:31:31 -04:00
1 parent f58cb7dfcf
commit a62cb42189
24 files changed
+318 -186

No files matched your search

@@ -117,9 +117,9 @@ class ComputedSkeletonBehaviour(
val targetState = receiver.context.state.value
// TODO find out a cleaner way to pause tracking that doesn't add 1 frame latency (not a priority)
val boneInputs = if (targetState.pausedBoneInputs != null) {
val boneInputs = if (targetState.pausedProcessedBoneInputs != null) {
// Use already-processed paused tracking data except for the head
targetState.pausedBoneInputs.mutateCopy { it[BodyPart.HEAD] = targetState.boneInputs[BodyPart.HEAD] }
targetState.pausedProcessedBoneInputs.mutateCopy { it[BodyPart.HEAD] = targetState.boneInputs[BodyPart.HEAD] }
} else {
// Run pre-FK processors
// TODO: Add a constrain processor (maybe not needed)
@@ -143,10 +143,10 @@ class ComputedSkeletonBehaviour(
val changedInputs = newInputs.filter { (part, boneInput) -> boneInput != inputs[part] }
fk = buildBones(newInputs, changedInputs.keys, fk)
// For bones with inactive position, update their input's position in state (needed for Localizer)
val changedPositionInputs = changedInputs.filter { (part, boneInput) -> boneInput.rawPosition != inputs[part]?.rawPosition }
// For changed bones with inactive positions, update their input's position in state (needed for Localizer)
val changedPositionInputs = changedInputs.filter { (part, boneInput) -> !boneInput.isPositionActive && boneInput.position != inputs[part]?.position }
for (input in changedPositionInputs) {
receiver.context.dispatch(SkeletonActions.SetBonePosition(input.key, input.value.rawPosition, false))
receiver.context.dispatch(SkeletonActions.SetBonePosition(input.key, input.value.position, false))
}
}
newInputs
@@ -39,8 +39,8 @@ class FootPlantFkProcessor(val settings: Settings) : SkeletonFkProcessor {
val input = it[bodyPart] ?: continue
val output = fk[bodyPart] ?: continue
it[bodyPart] = input.copy(
rawRotation = correctFootAttitude(
input.rawRotation,
rotation = correctFootAttitude(
input.rotation,
computeFootPlantRatio(
output.headPosition.y,
floorLevel,
@@ -1,6 +1,7 @@
package dev.slimevr.skeleton.fkprocessors
import dev.slimevr.config.Settings
import dev.slimevr.skeleton.BoneState
import dev.slimevr.skeleton.ComputedSkeleton
import dev.slimevr.skeleton.InputSkeleton
import dev.slimevr.skeleton.SkeletonFkProcessor
@@ -8,6 +9,96 @@ import dev.slimevr.skeleton.mutateCopy
import io.github.axisangles.ktmath.Vector3
import solarxr_protocol.datatypes.BodyPart
enum class MovementStates {
LEFT_LOCKED,
RIGHT_LOCKED,
NONE_LOCKED,
FOLLOW_FOOT,
FOLLOW_COM,
FOLLOW_SITTING,
}
private const val WARMUP_FRAMES = 100 // ~0.1 seconds
private const val MAX_FOOT_PERCENTAGE = 50.0f
private const val MAX_ACCEL_UP = 2.0f
private const val SITTING_KNEE_THRESHOLD = 1.1f
private const val SITTING_EARLY = 1000f
private const val VELOCITY_SAMPLE_RATE: Long = 100000000 // 10ms
private const val CONSTANT_ACCELERATION: Float = 2.0f
fun getPlantedFoot(fk: ComputedSkeleton): MovementStates {
val leftFoot = fk[BodyPart.LEFT_FOOT] ?: return MovementStates.NONE_LOCKED
val rightFoot = fk[BodyPart.RIGHT_FOOT] ?: return MovementStates.NONE_LOCKED
return if (leftFoot.headPosition.y < rightFoot.headPosition.y) {
MovementStates.LEFT_LOCKED
} else {
MovementStates.RIGHT_LOCKED
}
}
// check if the foot that is planted is actually planted
private fun getWorldReference(fk: ComputedSkeleton): MovementStates = if (isUserSitting(fk)) {
// User is sitting down
MovementStates.FOLLOW_SITTING
} else if (!isFootOnGround(fk)) {
// if the foot is not on the ground, use the COM
MovementStates.FOLLOW_COM
} else {
MovementStates.FOLLOW_FOOT
}
// Gets travel from a planted foot
private fun getPlantedFootTravel(fk: ComputedSkeleton): Vector3 {
// Which foot is planted
val plantedFoot = getPlantedFoot(fk)
val footBone = when (plantedFoot) {
MovementStates.LEFT_LOCKED -> fk[BodyPart.LEFT_FOOT]
MovementStates.RIGHT_LOCKED -> fk[BodyPart.RIGHT_FOOT]
else -> null
}
if (footBone == null) return Vector3.NULL
// Get foot travel
val footPosition: Vector3 = footBone.headPosition
return footPosition - Vector3.NULL
}
// Gets the sitting travel (emulates hip lock)
private fun computeSittingTravel(fk: ComputedSkeleton): Vector3 {
val hip = fk[BodyPart.HIP]?.headPosition ?: return Vector3.NULL
return Vector3.NULL
}
// Returns true if either foot's position is below 0
fun isFootOnGround(fk: ComputedSkeleton): Boolean {
val leftFoot = fk[BodyPart.LEFT_FOOT] ?: return false
val rightFoot = fk[BodyPart.RIGHT_FOOT] ?: return false
return leftFoot.headPosition.y <= 0f || rightFoot.headPosition.y <= 0f
}
// returns the bone closest to or furthest inside the ground
private fun getLowestBone(fk: ComputedSkeleton): BoneState = fk.minBy { it.value.headPosition.y }.value
// returns true if the user is likely sitting
// (assumes the floor is flat at 0.0)
private fun isUserSitting(fk: ComputedSkeleton): Boolean {
// based on the waist to knee vector decide if the user is sitting or
// standing (ie, if the user is sitting the vector will be pointing off
// to the side for both feet)
var leftKnee: Vector3 = fk[BodyPart.LEFT_UPPER_LEG]?.tailPosition ?: return false
var rightKnee: Vector3 = fk[BodyPart.RIGHT_UPPER_LEG]?.tailPosition ?: return false
val hip: Vector3 = fk[BodyPart.HIP]?.headPosition ?: return false
leftKnee = hip - leftKnee
rightKnee = hip - rightKnee
// if the y component of the vectors is small then the user is probably sitting
val sittingLeft = leftKnee.y * SITTING_KNEE_THRESHOLD < leftKnee.x + leftKnee.z
val sittingRight = rightKnee.y * SITTING_KNEE_THRESHOLD < rightKnee.x + rightKnee.z
return sittingLeft && sittingRight
}
class LocalizerFkProcessor(val settings: Settings) : SkeletonFkProcessor {
override fun process(inputSkeleton: InputSkeleton, fk: ComputedSkeleton, floorLevel: Float): InputSkeleton {
val headInput = inputSkeleton[BodyPart.HEAD] ?: return inputSkeleton
@@ -15,7 +106,17 @@ class LocalizerFkProcessor(val settings: Settings) : SkeletonFkProcessor {
return inputSkeleton
}
// TODO logic for this
return inputSkeleton.mutateCopy { updated -> updated[BodyPart.HEAD] = headInput.copy(rawPosition = headInput.rawPosition?.let { Vector3(it.x, it.y, it.z) }) }
val travel = when (getWorldReference(fk)) {
MovementStates.FOLLOW_FOOT -> getPlantedFootTravel(fk)
// MovementStates.FOLLOW_COM -> getCOMTravel(fk) TODO
MovementStates.FOLLOW_SITTING -> computeSittingTravel(fk)
else -> Vector3.NULL
}
val newHeadPosition = (headInput.position ?: Vector3.NULL) - travel
return inputSkeleton.mutateCopy { updated -> updated[BodyPart.HEAD] = headInput.copy(position = newHeadPosition) }
}
}
@@ -59,8 +59,8 @@ class ToeSnapFkProcessor(val settings: Settings) : SkeletonFkProcessor {
val input = it[bodyPart] ?: continue
val output = fk[bodyPart] ?: continue
it[bodyPart] = input.copy(
rawRotation = snapToes(
input.rawRotation,
rotation = snapToes(
input.rotation,
computeToeSnapRatio(
output.headPosition.y,
input.offset.len(),
@@ -86,7 +86,7 @@ fun rotateChain(
requireNotNull(boneInput) {
"The provided bone inputs are missing \"${bodyPart}\" from the IK chain."
}.copy(
rawRotation = rotation * boneInput.rawRotation,
rotation = rotation * boneInput.rotation,
)
}
}
@@ -31,7 +31,7 @@ class BoneActiveLinkInputProcessor : SkeletonInputProcessor {
val closestActiveBone = sources.firstNotNullOfOrNull { part ->
inputSkeleton[part]?.takeIf { it.isRotationActive }
} ?: continue
updated[bodyPart] = bone.copy(rawRotation = closestActiveBone.rawRotation)
updated[bodyPart] = bone.copy(rotation = closestActiveBone.rotation)
}
}
}
@@ -43,7 +43,7 @@ class BoneDirectLinkInputProcessor : SkeletonInputProcessor {
if (bone.isRotationActive) continue
val sourceBone = updated[source]
updated[bodyPart] = bone.copy(rawRotation = sourceBone?.rawRotation ?: bone.rawRotation)
updated[bodyPart] = bone.copy(rotation = sourceBone?.rotation ?: bone.rotation)
}
}
}
@@ -7,7 +7,6 @@ import dev.slimevr.skeleton.SkeletonInputProcessor
import dev.slimevr.skeleton.bodyPartMap
import dev.slimevr.skeleton.mapValues
import io.github.axisangles.ktmath.Quaternion
import io.github.axisangles.ktmath.Vector3
import solarxr_protocol.datatypes.BodyPart
import solarxr_protocol.rpc.FilteringType
@@ -18,7 +17,6 @@ class BonePredictionInputProcessor(val settings: Settings) : SkeletonInputProces
private data class BoneVelocity(
val lastRotation: Quaternion,
val rotationDelta: Quaternion,
val lastOffset: Vector3,
)
private var velocities: BodyPartMap<BoneVelocity> = bodyPartMap()
@@ -48,29 +46,21 @@ class BonePredictionInputProcessor(val settings: Settings) : SkeletonInputProces
val newBones = inputSkeleton.mapValues { bodyPart, bone ->
val prev = velocities[bodyPart]
if (prev == null) {
newVelocities[bodyPart] = BoneVelocity(bone.rawRotation, Quaternion.IDENTITY, bone.offset)
newVelocities[bodyPart] = BoneVelocity(bone.rotation, Quaternion.IDENTITY)
return@mapValues bone
}
val bonePredictionAmount = predictionAmount * getMultiplier(bodyPart)
val rotationDelta = if (bone.rawRotation !== prev.lastRotation) {
bone.rawRotation * prev.lastRotation.inv()
val rotationDelta = if (bone.rotation !== prev.lastRotation) {
bone.rotation * prev.lastRotation.inv()
} else {
prev.rotationDelta
}
// Offsets only move on a proportion change, so the delta must not carry across frames
val lengthDelta = if (bone.offset != prev.lastOffset) {
bone.offset - prev.lastOffset
} else {
Vector3.NULL
}
newVelocities[bodyPart] = BoneVelocity(bone.rawRotation, rotationDelta, bone.offset)
newVelocities[bodyPart] = BoneVelocity(bone.rotation, rotationDelta)
val scaledDelta = Quaternion.IDENTITY.lerpR(rotationDelta, bonePredictionAmount).unit()
bone.copy(
rawRotation = (scaledDelta * bone.rawRotation).unit(),
offset = bone.offset + lengthDelta * bonePredictionAmount,
)
bone.copy(rotation = (scaledDelta * bone.rotation).unit())
}
velocities = newVelocities
return newBones
@@ -9,16 +9,13 @@ import dev.slimevr.skeleton.mapValues
import dev.slimevr.util.inFloatingSeconds
import dev.slimevr.util.timeSource
import io.github.axisangles.ktmath.Quaternion
import io.github.axisangles.ktmath.Vector3
import solarxr_protocol.rpc.FilteringType
/**
* Running average of bones to smooth them out.
* Running average of bone rotations to smooth them out.
*/
class BoneSmoothingInputProcessor(val settings: Settings) : SkeletonInputProcessor {
private data class SmoothedBone(val rotation: Quaternion, val offset: Vector3)
private var smoothed: BodyPartMap<SmoothedBone> = bodyPartMap()
private var smoothed: BodyPartMap<Quaternion> = bodyPartMap()
private var lastProcessTime = timeSource.markNow()
// TODO this isn't linear. Do we want linear smoothing like in main?
@@ -38,13 +35,12 @@ class BoneSmoothingInputProcessor(val settings: Settings) : SkeletonInputProcess
val smoothingAmount = SMOOTH_MIN + config.amount.coerceIn(0f, 1f) * (SMOOTH_MAX - SMOOTH_MIN)
val alpha = ((1 - smoothingAmount) * lastFrameTimeSeconds * SMOOTHING_MULTIPLIER).coerceIn(0f, 1f)
val newSmoothed = bodyPartMap<SmoothedBone>()
val newSmoothed = bodyPartMap<Quaternion>()
val newBones = inputSkeleton.mapValues { bodyPart, bone ->
val prev = smoothed[bodyPart] ?: SmoothedBone(bone.rawRotation, bone.offset)
val rotation = prev.rotation.lerpR(bone.rawRotation, alpha).unit()
val offset = prev.offset + (bone.offset - prev.offset) * alpha
newSmoothed[bodyPart] = SmoothedBone(rotation, offset)
bone.copy(rawRotation = rotation, offset = offset)
val prev = smoothed[bodyPart] ?: bone.rotation
val rotation = prev.lerpR(bone.rotation, alpha).unit()
newSmoothed[bodyPart] = rotation
bone.copy(rotation = rotation)
}
smoothed = newSmoothed
return newBones
@@ -22,7 +22,7 @@ class BoneYawFallbackInputProcessor : SkeletonInputProcessor {
val childBone = inputSkeleton[childPart.second] ?: continue
if (childBone.isRotationActive) continue // Child needs to be inactive
updated[childPart.second] = childBone.copy(rawRotation = parentBone.rawRotation.project(Vector3.POS_Y).unit())
updated[childPart.second] = childBone.copy(rotation = parentBone.rotation.project(Vector3.POS_Y).unit())
}
}
}
@@ -54,7 +54,7 @@ class FingerImputeInputProcessor : SkeletonInputProcessor {
if (bone.isRotationActive) continue
val sourceBone = updated[source]
updated[bodyPart] = bone.copy(rawRotation = sourceBone?.rawRotation ?: bone.rawRotation)
updated[bodyPart] = bone.copy(rotation = sourceBone?.rotation ?: bone.rotation)
}
}
}
@@ -13,9 +13,9 @@ import solarxr_protocol.datatypes.BodyPart
class HeadPositionFallbackProcessor(val settings: Settings) : SkeletonInputProcessor {
override fun process(inputSkeleton: InputSkeleton, skeletonHeight: Float): InputSkeleton {
val headBone = inputSkeleton[BodyPart.HEAD] ?: return inputSkeleton
if (headBone.rawPosition != null) return inputSkeleton
if (headBone.position != null) return inputSkeleton
// Set the head position to the be standing up at the origin
return inputSkeleton.mutateCopy { it[BodyPart.HEAD] = headBone.copy(rawPosition = Vector3(0f, skeletonHeight, 0f)) }
return inputSkeleton.mutateCopy { it[BodyPart.HEAD] = headBone.copy(position = Vector3(0f, skeletonHeight, 0f)) }
}
}
@@ -4,7 +4,6 @@ import dev.slimevr.config.Settings
import dev.slimevr.skeleton.InputSkeleton
import dev.slimevr.skeleton.SkeletonInputProcessor
import dev.slimevr.skeleton.mutateCopy
import dev.slimevr.skeleton.resolveAverageRotationFor
import io.github.axisangles.ktmath.Quaternion
import solarxr_protocol.datatypes.BodyPart
@@ -12,18 +11,17 @@ import solarxr_protocol.datatypes.BodyPart
* Handles rotating the hip' yaw and roll to match the upper legs' yaw and roll.
*/
class HipYawRollAlignInputProcessor(val settings: Settings) : SkeletonInputProcessor {
val source = arrayOf(BodyPart.LEFT_UPPER_LEG, BodyPart.RIGHT_UPPER_LEG)
override fun process(inputSkeleton: InputSkeleton, skeletonHeight: Float): InputSkeleton {
val hipBone = inputSkeleton[BodyPart.HIP] ?: return inputSkeleton
if (hipBone.isRotationActive) return inputSkeleton
val leftUpperLegBone = inputSkeleton[BodyPart.LEFT_UPPER_LEG] ?: return inputSkeleton
val rightUpperLegBone = inputSkeleton[BodyPart.RIGHT_UPPER_LEG] ?: return inputSkeleton
return inputSkeleton.mutateCopy { updated ->
val ratio = settings.context.state.value.data.skeletonConfig.ratios.interpolateHipWithUpperLegs
val sourceRotation = updated.resolveAverageRotationFor(source)
val alignedRotation = alignYawRoll(hipBone.rawRotation, sourceRotation)
updated[BodyPart.HIP] = hipBone.copy(rawRotation = hipBone.rawRotation.interpQ(alignedRotation, ratio))
val sourceRotation = leftUpperLegBone.rotation.lerpQ(rightUpperLegBone.rotation, 0.5f)
val alignedRotation = alignYawRoll(hipBone.rotation, sourceRotation)
updated[BodyPart.HIP] = hipBone.copy(rotation = hipBone.rotation.interpQ(alignedRotation, ratio))
}
}
@@ -1,10 +1,11 @@
package dev.slimevr.skeleton.inputprocessors
import dev.slimevr.config.Settings
import dev.slimevr.skeleton.BoneInput
import dev.slimevr.skeleton.InputSkeleton
import dev.slimevr.skeleton.SkeletonInputProcessor
import dev.slimevr.skeleton.mutateCopy
import dev.slimevr.skeleton.resolveAverageRotationFor
import io.github.axisangles.ktmath.Quaternion
import solarxr_protocol.datatypes.BodyPart
/**
@@ -87,10 +88,10 @@ class SpineImputeInputProcessor(val settings: Settings) : SkeletonInputProcessor
reliabilityOf(bodyPart, toSource),
)
val fromRotation = inputSkeleton.resolveAverageRotationFor(fromSource.parts)
val toRotation = inputSkeleton.resolveAverageRotationFor(toSource.parts)
val fromRotation = averageRotation(inputSkeleton, fromSource.parts)
val toRotation = averageRotation(inputSkeleton, toSource.parts)
updated[bodyPart] = bone.copy(rawRotation = fromRotation.interpQ(toRotation, interpolateRatio))
updated[bodyPart] = bone.copy(rotation = fromRotation.interpQ(toRotation, interpolateRatio))
}
}
}
@@ -130,4 +131,12 @@ class SpineImputeInputProcessor(val settings: Settings) : SkeletonInputProcessor
}
private fun lerp(from: Float, to: Float, t: Float): Float = from + (to - from) * t
private fun averageRotation(inputSkeleton: InputSkeleton, takeBodyParts: Array<BodyPart> = arrayOf()): Quaternion {
val bonesToAverage = inputSkeleton.values.filter { it.bodyPart in takeBodyParts }
return bonesToAverage.map { it.rotation }
.reduceIndexedOrNull { index, acc, rotation ->
acc.lerpQ(rotation, 1f / (index + 1))
} ?: Quaternion.IDENTITY
}
}
@@ -34,7 +34,7 @@ class ToeDirectLinkInputProcessor : SkeletonInputProcessor {
if (bone.isRotationActive) continue
val sourceBone = updated[source]
updated[bodyPart] =
bone.copy(rawRotation = sourceBone?.rawRotation ?: bone.rawRotation)
bone.copy(rotation = sourceBone?.rotation ?: bone.rotation)
}
}
}
@@ -30,9 +30,9 @@ class UpperLegsRollAlignInputProcessor(val settings: Settings) : SkeletonInputPr
val bone = inputSkeleton[bodyPartToSource.first] ?: continue
if (!bone.isRotationActive) continue
val sourceRotation = inputSkeleton[bodyPartToSource.second]?.rawRotation ?: continue
val alignedRotation = alignRoll(bone.rawRotation, sourceRotation)
updated[bodyPartToSource.first] = bone.copy(rawRotation = bone.rawRotation.interpQ(alignedRotation, ratio))
val sourceRotation = inputSkeleton[bodyPartToSource.second]?.rotation ?: continue
val alignedRotation = alignRoll(bone.rotation, sourceRotation)
updated[bodyPartToSource.first] = bone.copy(rotation = bone.rotation.interpQ(alignedRotation, ratio))
}
}
}
@@ -5,7 +5,6 @@ import dev.slimevr.config.Settings
import dev.slimevr.context.Behaviour
import dev.slimevr.context.Context
import dev.slimevr.skeleton.fkprocessors.FootPlantFkProcessor
import dev.slimevr.skeleton.fkprocessors.LocalizerFkProcessor
import dev.slimevr.skeleton.fkprocessors.ToeSnapFkProcessor
import dev.slimevr.skeleton.inputprocessors.BoneActiveLinkInputProcessor
import dev.slimevr.skeleton.inputprocessors.BoneDirectLinkInputProcessor
@@ -29,19 +28,25 @@ import solarxr_protocol.rpc.SkeletonBone
data class BoneInput(
val bodyPart: BodyPart,
val offset: Vector3,
val rawRotation: Quaternion,
val rawPosition: Vector3?,
val rotation: Quaternion,
val acceleration: Vector3,
val position: Vector3?,
val isRotationActive: Boolean,
val isAccelerationActive: Boolean,
val isPositionActive: Boolean,
val angularVelocity: Vector3,
val linearVelocity: Vector3,
)
data class BoneState(
val parentBone: BoneState?,
val bodyPart: BodyPart,
val offset: Vector3,
val rotation: Quaternion = Quaternion.IDENTITY,
val headPosition: Vector3 = Vector3.NULL,
val tailPosition: Vector3 = Vector3.NULL,
val parentBone: BoneState? = null,
val rotation: Quaternion,
val headPosition: Vector3,
val tailPosition: Vector3,
val angularVelocity: Vector3,
val linearVelocity: Vector3,
) {
private val orientationOffset = when {
offset.len() == 0f -> Quaternion.IDENTITY
@@ -49,6 +54,7 @@ data class BoneState(
else -> Quaternion.fromTo(Vector3.NEG_Y, offset)
}
val orientation: Quaternion = rotation * orientationOffset
val localRotation: Quaternion
get() = parentBone?.let { it.rotation.inv() * rotation } ?: rotation
val localHeadPosition: Vector3
@@ -59,57 +65,47 @@ data class BoneState(
typealias InputSkeleton = BodyPartMap<BoneInput>
typealias ComputedSkeleton = BodyPartMap<BoneState>
@JvmName("resolveAverageRotationForInput")
fun InputSkeleton.resolveAverageRotationFor(bodyParts: Array<BodyPart>): Quaternion {
val rotations = bodyParts.mapNotNull { this[it]?.rawRotation }
return rotations.reduceIndexedOrNull { index, acc, rotation ->
acc.lerpQ(rotation, 1f / (index + 1))
} ?: Quaternion.IDENTITY
}
@JvmName("resolveAverageRotationForComputed")
fun ComputedSkeleton.resolveAverageRotationFor(bodyParts: Array<BodyPart>): Quaternion {
val rotations = bodyParts.mapNotNull { this[it]?.rotation }
return rotations.reduceIndexedOrNull { index, acc, rotation ->
acc.lerpQ(rotation, 1f / (index + 1))
} ?: Quaternion.IDENTITY
}
data class SkeletonState(
val boneInputs: InputSkeleton,
val skeletonHeight: Float,
val floorLevel: Float,
val paused: Boolean,
val pausedBoneInputs: InputSkeleton?,
val pausedProcessedBoneInputs: InputSkeleton?,
)
val DEFAULT_SKELETON_STATE: SkeletonState = SkeletonState(
boneInputs = DEFAULT_PROPORTIONS.toBoneOffsets().mapValues { bodyPart, tailOffset ->
BoneInput(
rawRotation = Quaternion.IDENTITY,
bodyPart = bodyPart,
offset = tailOffset,
rawPosition = null,
rotation = Quaternion.IDENTITY,
acceleration = Vector3.NULL,
position = null,
isRotationActive = false,
isAccelerationActive = false,
isPositionActive = false,
angularVelocity = Vector3.NULL,
linearVelocity = Vector3.NULL,
)
},
skeletonHeight = DEFAULT_HEIGHT,
floorLevel = 0f,
paused = false,
pausedBoneInputs = null,
pausedProcessedBoneInputs = null,
)
fun buildBone(bone: BoneInput, parentBone: BoneState?): BoneState {
// Raw position of the bone input is used for the head bone
val headPosition = parentBone?.tailPosition ?: bone.rawPosition ?: Vector3.NULL
// Raw position of the bone input is used for BodyPart.HEAD since it has no parent
val headPosition = parentBone?.tailPosition ?: bone.position ?: Vector3.NULL
return BoneState(
parentBone = parentBone,
bodyPart = bone.bodyPart,
offset = bone.offset,
rotation = bone.rotation,
headPosition = headPosition,
rotation = bone.rawRotation,
tailPosition = headPosition + bone.rawRotation.sandwich(bone.offset),
parentBone = parentBone,
tailPosition = headPosition + bone.rotation.sandwich(bone.offset),
angularVelocity = bone.angularVelocity,
linearVelocity = bone.linearVelocity,
)
}
@@ -132,13 +128,14 @@ fun buildBones(boneInputs: InputSkeleton, changedParts: Set<BodyPart> = headPart
sealed interface SkeletonActions {
data class SetBoneRotation(val bodyPart: BodyPart, val rotation: Quaternion, val setActive: Boolean = true) : SkeletonActions
data class SetBoneAcceleration(val bodyPart: BodyPart, val acceleration: Vector3, val setActive: Boolean = true) : SkeletonActions
data class SetBonePosition(val bodyPart: BodyPart, val position: Vector3?, val setActive: Boolean = true) : SkeletonActions
data class DisableBone(val bodyPart: BodyPart) : SkeletonActions
data class SetProportions(val lengths: Map<SkeletonBone, Float>) : SkeletonActions
data class PauseTracking(val pause: Boolean) : SkeletonActions
data class SetPausedBoneInputs(val pausedBoneInputs: InputSkeleton) : SkeletonActions
data object ComputeFloorLevel : SkeletonActions
data object ResetHeadPosition : SkeletonActions
data object ComputeFloorLevel : SkeletonActions
}
typealias SkeletonContext = Context<SkeletonState, SkeletonActions>
@@ -164,7 +161,7 @@ class Skeleton(
fun startObserving() = context.observeAll(this)
companion object {
const val DEFAULT_HZ = 300
const val DEFAULT_HZ = 400
fun create(scope: CoroutineScope, ctx: Phase1ContextProvider, hz: Int = DEFAULT_HZ): Skeleton {
val settings = ctx.config.settings
@@ -189,7 +186,7 @@ class Skeleton(
BoneSmoothingInputProcessor(settings),
),
fkProcessors = listOf(
LocalizerFkProcessor(settings),
// LocalizerFkProcessor(settings),
FootPlantFkProcessor(settings),
ToeSnapFkProcessor(settings),
),
@@ -1,22 +1,39 @@
package dev.slimevr.skeleton
import io.github.axisangles.ktmath.Quaternion
import io.github.axisangles.ktmath.Vector3
import solarxr_protocol.datatypes.BodyPart
fun reduce(state: SkeletonState, action: SkeletonActions): SkeletonState = when (action) {
is SkeletonActions.SetBoneRotation -> {
val bone = state.boneInputs[action.bodyPart] ?: return state
state.copy(boneInputs = state.boneInputs.mutateCopy { it[action.bodyPart] = bone.copy(rawRotation = action.rotation, isRotationActive = action.setActive) })
state.copy(boneInputs = state.boneInputs.mutateCopy { it[action.bodyPart] = bone.copy(rotation = action.rotation, isRotationActive = action.setActive) })
}
is SkeletonActions.SetBoneAcceleration -> {
val bone = state.boneInputs[action.bodyPart] ?: return state
state.copy(boneInputs = state.boneInputs.mutateCopy { it[action.bodyPart] = bone.copy(acceleration = action.acceleration, isAccelerationActive = action.setActive) })
}
is SkeletonActions.SetBonePosition -> {
val bone = state.boneInputs[action.bodyPart] ?: return state
state.copy(boneInputs = state.boneInputs.mutateCopy { it[action.bodyPart] = bone.copy(rawPosition = action.position, isPositionActive = action.setActive) })
state.copy(boneInputs = state.boneInputs.mutateCopy { it[action.bodyPart] = bone.copy(position = action.position, isPositionActive = action.setActive) })
}
is SkeletonActions.DisableBone -> {
val bone = state.boneInputs[action.bodyPart] ?: return state
state.copy(boneInputs = state.boneInputs.mutateCopy { it[action.bodyPart] = bone.copy(rawRotation = Quaternion.IDENTITY, rawPosition = null, isRotationActive = false, isPositionActive = false) })
state.copy(
boneInputs = state.boneInputs.mutateCopy {
it[action.bodyPart] = bone.copy(
rotation = Quaternion.IDENTITY,
acceleration = Vector3.NULL,
position = null,
isRotationActive = false,
isAccelerationActive = false,
isPositionActive = false,
)
},
)
}
is SkeletonActions.SetProportions -> {
@@ -27,20 +44,20 @@ fun reduce(state: SkeletonState, action: SkeletonActions): SkeletonState = when
state.copy(boneInputs = newBones, skeletonHeight = action.lengths.height())
}
is SkeletonActions.PauseTracking -> state.copy(paused = action.pause, pausedBoneInputs = null)
is SkeletonActions.PauseTracking -> state.copy(paused = action.pause, pausedProcessedBoneInputs = null)
is SkeletonActions.SetPausedBoneInputs -> state.copy(pausedBoneInputs = action.pausedBoneInputs)
is SkeletonActions.ComputeFloorLevel -> {
val skeletonHeight = state.skeletonHeight
val headHeight = state.boneInputs[BodyPart.HEAD]?.rawPosition?.y ?: skeletonHeight
state.copy(floorLevel = headHeight - skeletonHeight)
}
is SkeletonActions.SetPausedBoneInputs -> state.copy(pausedProcessedBoneInputs = action.pausedBoneInputs)
is SkeletonActions.ResetHeadPosition -> {
val boneInputs = state.boneInputs
val headBone = boneInputs[BodyPart.HEAD] ?: return state
if (headBone.isPositionActive) return state
state.copy(boneInputs = boneInputs.mutateCopy { it[BodyPart.HEAD] = headBone.copy(rawPosition = null) })
state.copy(boneInputs = boneInputs.mutateCopy { it[BodyPart.HEAD] = headBone.copy(position = null) })
}
is SkeletonActions.ComputeFloorLevel -> {
val skeletonHeight = state.skeletonHeight
val headHeight = state.boneInputs[BodyPart.HEAD]?.position?.y ?: skeletonHeight
state.copy(floorLevel = headHeight - skeletonHeight)
}
}
@@ -124,7 +124,7 @@ class TapDetectionBasicBehaviour : TapDetectionBehaviour {
othersOverThreshold >= numberTrackersOverThreshold,
trackerTapDetectionState,
rawAcceleration,
motionState,
Motion.RESTING, // TODO motionState, disabled bc ZRock doesn't like it
)
if (tapTriggered) {
@@ -42,6 +42,7 @@ class TrackerToSkeletonBehaviour : TrackerBehaviour {
receiver.appContext.skeleton.context.dispatchAll(
listOfNotNull(
SkeletonActions.SetBoneRotation(bodyPart, trackerState.rotation),
SkeletonActions.SetBoneAcceleration(bodyPart, trackerState.acceleration),
if (trackerState.position != null) SkeletonActions.SetBonePosition(bodyPart, trackerState.position) else null,
),
)
@@ -19,12 +19,12 @@ class BvhStreamTest {
val initialBones = buildBones(DEFAULT_SKELETON_STATE.boneInputs)
val firstFrame = buildBones(
DEFAULT_SKELETON_STATE.boneInputs.mutateCopy {
it[BodyPart.HEAD] = it.getValue(BodyPart.HEAD).copy(rawPosition = Vector3(1f, 2f, 3f))
it[BodyPart.HEAD] = it.getValue(BodyPart.HEAD).copy(position = Vector3(1f, 2f, 3f))
},
)
val secondFrame = buildBones(
DEFAULT_SKELETON_STATE.boneInputs.mutateCopy {
it[BodyPart.HEAD] = it.getValue(BodyPart.HEAD).copy(rawPosition = Vector3(4f, 5f, 6f))
it[BodyPart.HEAD] = it.getValue(BodyPart.HEAD).copy(position = Vector3(4f, 5f, 6f))
},
)
@@ -54,7 +54,7 @@ class BvhStreamTest {
stream.writeFrame(
buildBones(
DEFAULT_SKELETON_STATE.boneInputs.mutateCopy {
it[BodyPart.HEAD] = it.getValue(BodyPart.HEAD).copy(rawPosition = Vector3(7f, 8f, 9f))
it[BodyPart.HEAD] = it.getValue(BodyPart.HEAD).copy(position = Vector3(7f, 8f, 9f))
},
),
)
@@ -13,42 +13,62 @@ class IKTest {
boneInputs[BodyPart.NECK] = BoneInput(
bodyPart = BodyPart.NECK,
offset = Vector3.NEG_Y,
rawRotation = Quaternion.IDENTITY,
rawPosition = Vector3.NULL,
rotation = Quaternion.IDENTITY,
position = Vector3.NULL,
acceleration = Vector3.NULL,
isRotationActive = false,
isPositionActive = false,
isAccelerationActive = false,
angularVelocity = Vector3.NULL,
linearVelocity = Vector3.NULL,
)
boneInputs[BodyPart.UPPER_CHEST] = BoneInput(
bodyPart = BodyPart.UPPER_CHEST,
offset = Vector3.NEG_Y,
rawRotation = Quaternion.IDENTITY,
rawPosition = Vector3.NULL,
rotation = Quaternion.IDENTITY,
position = Vector3.NULL,
acceleration = Vector3.NULL,
isRotationActive = false,
isPositionActive = false,
isAccelerationActive = false,
angularVelocity = Vector3.NULL,
linearVelocity = Vector3.NULL,
)
boneInputs[BodyPart.CHEST] = BoneInput(
bodyPart = BodyPart.CHEST,
offset = Vector3.NEG_Y,
rawRotation = Quaternion.IDENTITY,
rawPosition = Vector3.NULL,
rotation = Quaternion.IDENTITY,
position = Vector3.NULL,
acceleration = Vector3.NULL,
isRotationActive = false,
isPositionActive = false,
isAccelerationActive = false,
angularVelocity = Vector3.NULL,
linearVelocity = Vector3.NULL,
)
boneInputs[BodyPart.WAIST] = BoneInput(
bodyPart = BodyPart.WAIST,
offset = Vector3.NEG_Y,
rawRotation = Quaternion.IDENTITY,
rawPosition = Vector3.NULL,
rotation = Quaternion.IDENTITY,
position = Vector3.NULL,
acceleration = Vector3.NULL,
isRotationActive = false,
isPositionActive = false,
isAccelerationActive = false,
angularVelocity = Vector3.NULL,
linearVelocity = Vector3.NULL,
)
boneInputs[BodyPart.HIP] = BoneInput(
bodyPart = BodyPart.HIP,
offset = Vector3.NEG_Y,
rawRotation = Quaternion.IDENTITY,
rawPosition = Vector3.NULL,
rotation = Quaternion.IDENTITY,
position = Vector3.NULL,
acceleration = Vector3.NULL,
isRotationActive = false,
isPositionActive = false,
isAccelerationActive = false,
angularVelocity = Vector3.NULL,
linearVelocity = Vector3.NULL,
)
val bones = buildBones(boneInputs)
@@ -12,11 +12,11 @@ class ToeDirectLinkProcessorTest {
val processor = ToeDirectLinkInputProcessor()
val inputs = DEFAULT_SKELETON_STATE.boneInputs.mutateCopy { map ->
map[BodyPart.LEFT_FOOT] = map.getValue(BodyPart.LEFT_FOOT).copy(
rawRotation = Quaternion.fromRotationVector(10f, 40f, 15f),
rotation = Quaternion.fromRotationVector(10f, 40f, 15f),
isRotationActive = true,
)
map[BodyPart.RIGHT_FOOT] = map.getValue(BodyPart.RIGHT_FOOT).copy(
rawRotation = Quaternion.fromRotationVector(20f, 50f, 25f),
rotation = Quaternion.fromRotationVector(20f, 50f, 25f),
isRotationActive = true,
)
}
@@ -26,32 +26,32 @@ class ToeDirectLinkProcessorTest {
skeletonHeight = 1.7f,
floorLevel = 0f,
paused = false,
pausedBoneInputs = inputs,
pausedProcessedBoneInputs = inputs,
)
val newInputs = processor.process(state.boneInputs, state.skeletonHeight)
val leftBigToeIsSameRotationAsLeftFoot =
newInputs[BodyPart.LEFT_BIG_TOE]?.rawRotation == newInputs[BodyPart.LEFT_FOOT]?.rawRotation
newInputs[BodyPart.LEFT_BIG_TOE]?.rotation == newInputs[BodyPart.LEFT_FOOT]?.rotation
val leftIndexToeIsSameRotationAsLeftBigToe =
newInputs[BodyPart.LEFT_INDEX_TOE]?.rawRotation == newInputs[BodyPart.LEFT_BIG_TOE]?.rawRotation
newInputs[BodyPart.LEFT_INDEX_TOE]?.rotation == newInputs[BodyPart.LEFT_BIG_TOE]?.rotation
val leftMiddleToeIsSameRotationAsLeftIndexToe =
newInputs[BodyPart.LEFT_MIDDLE_TOE]?.rawRotation == newInputs[BodyPart.LEFT_INDEX_TOE]?.rawRotation
newInputs[BodyPart.LEFT_MIDDLE_TOE]?.rotation == newInputs[BodyPart.LEFT_INDEX_TOE]?.rotation
val leftRingToeIsSameRotationAsLeftMiddleToe =
newInputs[BodyPart.LEFT_RING_TOE]?.rawRotation == newInputs[BodyPart.LEFT_MIDDLE_TOE]?.rawRotation
newInputs[BodyPart.LEFT_RING_TOE]?.rotation == newInputs[BodyPart.LEFT_MIDDLE_TOE]?.rotation
val leftLittleToeIsSameRotationAsLeftRingToe =
newInputs[BodyPart.LEFT_LITTLE_TOE]?.rawRotation == newInputs[BodyPart.LEFT_RING_TOE]?.rawRotation
newInputs[BodyPart.LEFT_LITTLE_TOE]?.rotation == newInputs[BodyPart.LEFT_RING_TOE]?.rotation
val rightBigToeIsSameRotationAsRightFoot =
newInputs[BodyPart.RIGHT_BIG_TOE]?.rawRotation == newInputs[BodyPart.RIGHT_FOOT]?.rawRotation
newInputs[BodyPart.RIGHT_BIG_TOE]?.rotation == newInputs[BodyPart.RIGHT_FOOT]?.rotation
val rightIndexToeIsSameRotationAsRightBigToe =
newInputs[BodyPart.RIGHT_INDEX_TOE]?.rawRotation == newInputs[BodyPart.RIGHT_BIG_TOE]?.rawRotation
newInputs[BodyPart.RIGHT_INDEX_TOE]?.rotation == newInputs[BodyPart.RIGHT_BIG_TOE]?.rotation
val rightMiddleToeIsSameRotationAsRightIndexToe =
newInputs[BodyPart.RIGHT_MIDDLE_TOE]?.rawRotation == newInputs[BodyPart.RIGHT_INDEX_TOE]?.rawRotation
newInputs[BodyPart.RIGHT_MIDDLE_TOE]?.rotation == newInputs[BodyPart.RIGHT_INDEX_TOE]?.rotation
val rightRingToeIsSameRotationAsRightMiddleToe =
newInputs[BodyPart.RIGHT_RING_TOE]?.rawRotation == newInputs[BodyPart.RIGHT_MIDDLE_TOE]?.rawRotation
newInputs[BodyPart.RIGHT_RING_TOE]?.rotation == newInputs[BodyPart.RIGHT_MIDDLE_TOE]?.rotation
val rightLittleToeIsSameRotationAsRightRingToe =
newInputs[BodyPart.RIGHT_LITTLE_TOE]?.rawRotation == newInputs[BodyPart.RIGHT_RING_TOE]?.rawRotation
newInputs[BodyPart.RIGHT_LITTLE_TOE]?.rotation == newInputs[BodyPart.RIGHT_RING_TOE]?.rotation
assertTrue(
leftBigToeIsSameRotationAsLeftFoot &&
@@ -74,19 +74,19 @@ class ToeDirectLinkProcessorTest {
val processor = ToeDirectLinkInputProcessor()
val inputs = DEFAULT_SKELETON_STATE.boneInputs.mutateCopy { map ->
map[BodyPart.LEFT_FOOT] = map.getValue(BodyPart.LEFT_FOOT).copy(
rawRotation = Quaternion.fromRotationVector(10f, 40f, 15f),
rotation = Quaternion.fromRotationVector(10f, 40f, 15f),
isRotationActive = true,
)
map[BodyPart.LEFT_BIG_TOE] = map.getValue(BodyPart.LEFT_BIG_TOE).copy(
rawRotation = Quaternion.fromRotationVector(11f, 41f, 16f),
rotation = Quaternion.fromRotationVector(11f, 41f, 16f),
isRotationActive = true,
)
map[BodyPart.RIGHT_FOOT] = map.getValue(BodyPart.RIGHT_FOOT).copy(
rawRotation = Quaternion.fromRotationVector(20f, 50f, 25f),
rotation = Quaternion.fromRotationVector(20f, 50f, 25f),
isRotationActive = true,
)
map[BodyPart.RIGHT_BIG_TOE] = map.getValue(BodyPart.RIGHT_BIG_TOE).copy(
rawRotation = Quaternion.fromRotationVector(21f, 51f, 26f),
rotation = Quaternion.fromRotationVector(21f, 51f, 26f),
isRotationActive = true,
)
}
@@ -96,28 +96,28 @@ class ToeDirectLinkProcessorTest {
skeletonHeight = 1.7f,
floorLevel = 0f,
paused = false,
pausedBoneInputs = inputs,
pausedProcessedBoneInputs = inputs,
)
val newInputs = processor.process(state.boneInputs, state.skeletonHeight)
val leftIndexToeIsSameRotationAsLeftBigToe =
newInputs[BodyPart.LEFT_INDEX_TOE]?.rawRotation == newInputs[BodyPart.LEFT_BIG_TOE]?.rawRotation
newInputs[BodyPart.LEFT_INDEX_TOE]?.rotation == newInputs[BodyPart.LEFT_BIG_TOE]?.rotation
val leftMiddleToeIsSameRotationAsLeftIndexToe =
newInputs[BodyPart.LEFT_MIDDLE_TOE]?.rawRotation == newInputs[BodyPart.LEFT_INDEX_TOE]?.rawRotation
newInputs[BodyPart.LEFT_MIDDLE_TOE]?.rotation == newInputs[BodyPart.LEFT_INDEX_TOE]?.rotation
val leftRingToeIsSameRotationAsLeftMiddleToe =
newInputs[BodyPart.LEFT_RING_TOE]?.rawRotation == newInputs[BodyPart.LEFT_MIDDLE_TOE]?.rawRotation
newInputs[BodyPart.LEFT_RING_TOE]?.rotation == newInputs[BodyPart.LEFT_MIDDLE_TOE]?.rotation
val leftLittleToeIsSameRotationAsLeftRingToe =
newInputs[BodyPart.LEFT_LITTLE_TOE]?.rawRotation == newInputs[BodyPart.LEFT_RING_TOE]?.rawRotation
newInputs[BodyPart.LEFT_LITTLE_TOE]?.rotation == newInputs[BodyPart.LEFT_RING_TOE]?.rotation
val rightIndexToeIsSameRotationAsRightBigToe =
newInputs[BodyPart.RIGHT_INDEX_TOE]?.rawRotation == newInputs[BodyPart.RIGHT_BIG_TOE]?.rawRotation
newInputs[BodyPart.RIGHT_INDEX_TOE]?.rotation == newInputs[BodyPart.RIGHT_BIG_TOE]?.rotation
val rightMiddleToeIsSameRotationAsRightIndexToe =
newInputs[BodyPart.RIGHT_MIDDLE_TOE]?.rawRotation == newInputs[BodyPart.RIGHT_INDEX_TOE]?.rawRotation
newInputs[BodyPart.RIGHT_MIDDLE_TOE]?.rotation == newInputs[BodyPart.RIGHT_INDEX_TOE]?.rotation
val rightRingToeIsSameRotationAsRightMiddleToe =
newInputs[BodyPart.RIGHT_RING_TOE]?.rawRotation == newInputs[BodyPart.RIGHT_MIDDLE_TOE]?.rawRotation
newInputs[BodyPart.RIGHT_RING_TOE]?.rotation == newInputs[BodyPart.RIGHT_MIDDLE_TOE]?.rotation
val rightLittleToeIsSameRotationAsRightRingToe =
newInputs[BodyPart.RIGHT_LITTLE_TOE]?.rawRotation == newInputs[BodyPart.RIGHT_RING_TOE]?.rawRotation
newInputs[BodyPart.RIGHT_LITTLE_TOE]?.rotation == newInputs[BodyPart.RIGHT_RING_TOE]?.rotation
assertTrue(
leftIndexToeIsSameRotationAsLeftBigToe &&
@@ -138,28 +138,28 @@ class ToeDirectLinkProcessorTest {
val processor = ToeDirectLinkInputProcessor()
val inputs = DEFAULT_SKELETON_STATE.boneInputs.mutateCopy { map ->
map[BodyPart.LEFT_FOOT] = map.getValue(BodyPart.LEFT_FOOT).copy(
rawRotation = Quaternion.fromRotationVector(10f, 40f, 15f),
rotation = Quaternion.fromRotationVector(10f, 40f, 15f),
isRotationActive = true,
)
map[BodyPart.LEFT_BIG_TOE] = map.getValue(BodyPart.LEFT_BIG_TOE).copy(
rawRotation = Quaternion.fromRotationVector(11f, 41f, 16f),
rotation = Quaternion.fromRotationVector(11f, 41f, 16f),
isRotationActive = true,
)
map[BodyPart.LEFT_INDEX_TOE] = map.getValue(BodyPart.LEFT_INDEX_TOE).copy(
rawRotation = Quaternion.fromRotationVector(12f, 42f, 17f),
rotation = Quaternion.fromRotationVector(12f, 42f, 17f),
isRotationActive = true,
)
map[BodyPart.RIGHT_FOOT] = map.getValue(BodyPart.RIGHT_FOOT).copy(
rawRotation = Quaternion.fromRotationVector(20f, 50f, 25f),
rotation = Quaternion.fromRotationVector(20f, 50f, 25f),
isRotationActive = true,
)
map[BodyPart.RIGHT_BIG_TOE] = map.getValue(BodyPart.RIGHT_BIG_TOE).copy(
rawRotation = Quaternion.fromRotationVector(21f, 51f, 26f),
rotation = Quaternion.fromRotationVector(21f, 51f, 26f),
isRotationActive = true,
)
map[BodyPart.RIGHT_INDEX_TOE] = map.getValue(BodyPart.RIGHT_INDEX_TOE).copy(
rawRotation = Quaternion.fromRotationVector(22f, 52f, 27f),
rotation = Quaternion.fromRotationVector(22f, 52f, 27f),
isRotationActive = true,
)
}
@@ -169,24 +169,24 @@ class ToeDirectLinkProcessorTest {
skeletonHeight = 1.7f,
floorLevel = 0f,
paused = false,
pausedBoneInputs = inputs,
pausedProcessedBoneInputs = inputs,
)
val newInputs = processor.process(state.boneInputs, state.skeletonHeight)
val leftMiddleToeIsSameRotationAsLeftIndexToe =
newInputs[BodyPart.LEFT_MIDDLE_TOE]?.rawRotation == newInputs[BodyPart.LEFT_INDEX_TOE]?.rawRotation
newInputs[BodyPart.LEFT_MIDDLE_TOE]?.rotation == newInputs[BodyPart.LEFT_INDEX_TOE]?.rotation
val leftRingToeIsSameRotationAsLeftMiddleToe =
newInputs[BodyPart.LEFT_RING_TOE]?.rawRotation == newInputs[BodyPart.LEFT_MIDDLE_TOE]?.rawRotation
newInputs[BodyPart.LEFT_RING_TOE]?.rotation == newInputs[BodyPart.LEFT_MIDDLE_TOE]?.rotation
val leftLittleToeIsSameRotationAsLeftRingToe =
newInputs[BodyPart.LEFT_LITTLE_TOE]?.rawRotation == newInputs[BodyPart.LEFT_RING_TOE]?.rawRotation
newInputs[BodyPart.LEFT_LITTLE_TOE]?.rotation == newInputs[BodyPart.LEFT_RING_TOE]?.rotation
val rightMiddleToeIsSameRotationAsRightIndexToe =
newInputs[BodyPart.RIGHT_MIDDLE_TOE]?.rawRotation == newInputs[BodyPart.RIGHT_INDEX_TOE]?.rawRotation
newInputs[BodyPart.RIGHT_MIDDLE_TOE]?.rotation == newInputs[BodyPart.RIGHT_INDEX_TOE]?.rotation
val rightRingToeIsSameRotationAsRightMiddleToe =
newInputs[BodyPart.RIGHT_RING_TOE]?.rawRotation == newInputs[BodyPart.RIGHT_MIDDLE_TOE]?.rawRotation
newInputs[BodyPart.RIGHT_RING_TOE]?.rotation == newInputs[BodyPart.RIGHT_MIDDLE_TOE]?.rotation
val rightLittleToeIsSameRotationAsRightRingToe =
newInputs[BodyPart.RIGHT_LITTLE_TOE]?.rawRotation == newInputs[BodyPart.RIGHT_RING_TOE]?.rawRotation
newInputs[BodyPart.RIGHT_LITTLE_TOE]?.rotation == newInputs[BodyPart.RIGHT_RING_TOE]?.rotation
assertTrue(
leftMiddleToeIsSameRotationAsLeftIndexToe &&
@@ -205,36 +205,36 @@ class ToeDirectLinkProcessorTest {
val processor = ToeDirectLinkInputProcessor()
val inputs = DEFAULT_SKELETON_STATE.boneInputs.mutateCopy { map ->
map[BodyPart.LEFT_FOOT] = map.getValue(BodyPart.LEFT_FOOT).copy(
rawRotation = Quaternion.fromRotationVector(10f, 40f, 15f),
rotation = Quaternion.fromRotationVector(10f, 40f, 15f),
isRotationActive = true,
)
map[BodyPart.LEFT_BIG_TOE] = map.getValue(BodyPart.LEFT_BIG_TOE).copy(
rawRotation = Quaternion.fromRotationVector(11f, 41f, 16f),
rotation = Quaternion.fromRotationVector(11f, 41f, 16f),
isRotationActive = true,
)
map[BodyPart.LEFT_INDEX_TOE] = map.getValue(BodyPart.LEFT_INDEX_TOE).copy(
rawRotation = Quaternion.fromRotationVector(12f, 42f, 17f),
rotation = Quaternion.fromRotationVector(12f, 42f, 17f),
isRotationActive = true,
)
map[BodyPart.LEFT_MIDDLE_TOE] = map.getValue(BodyPart.LEFT_MIDDLE_TOE).copy(
rawRotation = Quaternion.fromRotationVector(13f, 43f, 18f),
rotation = Quaternion.fromRotationVector(13f, 43f, 18f),
isRotationActive = true,
)
map[BodyPart.RIGHT_FOOT] = map.getValue(BodyPart.RIGHT_FOOT).copy(
rawRotation = Quaternion.fromRotationVector(20f, 50f, 25f),
rotation = Quaternion.fromRotationVector(20f, 50f, 25f),
isRotationActive = true,
)
map[BodyPart.RIGHT_BIG_TOE] = map.getValue(BodyPart.RIGHT_BIG_TOE).copy(
rawRotation = Quaternion.fromRotationVector(21f, 51f, 26f),
rotation = Quaternion.fromRotationVector(21f, 51f, 26f),
isRotationActive = true,
)
map[BodyPart.RIGHT_INDEX_TOE] = map.getValue(BodyPart.RIGHT_INDEX_TOE).copy(
rawRotation = Quaternion.fromRotationVector(22f, 52f, 27f),
rotation = Quaternion.fromRotationVector(22f, 52f, 27f),
isRotationActive = true,
)
map[BodyPart.RIGHT_MIDDLE_TOE] = map.getValue(BodyPart.RIGHT_MIDDLE_TOE).copy(
rawRotation = Quaternion.fromRotationVector(23f, 53f, 28f),
rotation = Quaternion.fromRotationVector(23f, 53f, 28f),
isRotationActive = true,
)
}
@@ -244,20 +244,20 @@ class ToeDirectLinkProcessorTest {
skeletonHeight = 1.7f,
floorLevel = 0f,
paused = false,
pausedBoneInputs = inputs,
pausedProcessedBoneInputs = inputs,
)
val newInputs = processor.process(state.boneInputs, state.skeletonHeight)
val leftRingToeIsSameRotationAsLeftMiddleToe =
newInputs[BodyPart.LEFT_RING_TOE]?.rawRotation == newInputs[BodyPart.LEFT_MIDDLE_TOE]?.rawRotation
newInputs[BodyPart.LEFT_RING_TOE]?.rotation == newInputs[BodyPart.LEFT_MIDDLE_TOE]?.rotation
val leftLittleToeIsSameRotationAsLeftRingToe =
newInputs[BodyPart.LEFT_LITTLE_TOE]?.rawRotation == newInputs[BodyPart.LEFT_RING_TOE]?.rawRotation
newInputs[BodyPart.LEFT_LITTLE_TOE]?.rotation == newInputs[BodyPart.LEFT_RING_TOE]?.rotation
val rightRingToeIsSameRotationAsRightMiddleToe =
newInputs[BodyPart.RIGHT_RING_TOE]?.rawRotation == newInputs[BodyPart.RIGHT_MIDDLE_TOE]?.rawRotation
newInputs[BodyPart.RIGHT_RING_TOE]?.rotation == newInputs[BodyPart.RIGHT_MIDDLE_TOE]?.rotation
val rightLittleToeIsSameRotationAsRightRingToe =
newInputs[BodyPart.RIGHT_LITTLE_TOE]?.rawRotation == newInputs[BodyPart.RIGHT_RING_TOE]?.rawRotation
newInputs[BodyPart.RIGHT_LITTLE_TOE]?.rotation == newInputs[BodyPart.RIGHT_RING_TOE]?.rotation
assertTrue(leftRingToeIsSameRotationAsLeftMiddleToe && leftLittleToeIsSameRotationAsLeftRingToe)
assertTrue(rightRingToeIsSameRotationAsRightMiddleToe && rightLittleToeIsSameRotationAsRightRingToe)
@@ -268,44 +268,44 @@ class ToeDirectLinkProcessorTest {
val processor = ToeDirectLinkInputProcessor()
val inputs = DEFAULT_SKELETON_STATE.boneInputs.mutateCopy { map ->
map[BodyPart.LEFT_FOOT] = map.getValue(BodyPart.LEFT_FOOT).copy(
rawRotation = Quaternion.fromRotationVector(10f, 40f, 15f),
rotation = Quaternion.fromRotationVector(10f, 40f, 15f),
isRotationActive = true,
)
map[BodyPart.LEFT_BIG_TOE] = map.getValue(BodyPart.LEFT_BIG_TOE).copy(
rawRotation = Quaternion.fromRotationVector(11f, 41f, 16f),
rotation = Quaternion.fromRotationVector(11f, 41f, 16f),
isRotationActive = true,
)
map[BodyPart.LEFT_INDEX_TOE] = map.getValue(BodyPart.LEFT_INDEX_TOE).copy(
rawRotation = Quaternion.fromRotationVector(12f, 42f, 17f),
rotation = Quaternion.fromRotationVector(12f, 42f, 17f),
isRotationActive = true,
)
map[BodyPart.LEFT_MIDDLE_TOE] = map.getValue(BodyPart.LEFT_MIDDLE_TOE).copy(
rawRotation = Quaternion.fromRotationVector(15f, 45f, 19f),
rotation = Quaternion.fromRotationVector(15f, 45f, 19f),
isRotationActive = true,
)
map[BodyPart.LEFT_RING_TOE] = map.getValue(BodyPart.LEFT_RING_TOE).copy(
rawRotation = Quaternion.fromRotationVector(13f, 43f, 18f),
rotation = Quaternion.fromRotationVector(13f, 43f, 18f),
isRotationActive = true,
)
map[BodyPart.RIGHT_FOOT] = map.getValue(BodyPart.RIGHT_FOOT).copy(
rawRotation = Quaternion.fromRotationVector(20f, 50f, 25f),
rotation = Quaternion.fromRotationVector(20f, 50f, 25f),
isRotationActive = true,
)
map[BodyPart.RIGHT_BIG_TOE] = map.getValue(BodyPart.RIGHT_BIG_TOE).copy(
rawRotation = Quaternion.fromRotationVector(21f, 51f, 26f),
rotation = Quaternion.fromRotationVector(21f, 51f, 26f),
isRotationActive = true,
)
map[BodyPart.RIGHT_INDEX_TOE] = map.getValue(BodyPart.RIGHT_INDEX_TOE).copy(
rawRotation = Quaternion.fromRotationVector(22f, 52f, 27f),
rotation = Quaternion.fromRotationVector(22f, 52f, 27f),
isRotationActive = true,
)
map[BodyPart.RIGHT_MIDDLE_TOE] = map.getValue(BodyPart.RIGHT_MIDDLE_TOE).copy(
rawRotation = Quaternion.fromRotationVector(23f, 53f, 28f),
rotation = Quaternion.fromRotationVector(23f, 53f, 28f),
isRotationActive = true,
)
map[BodyPart.RIGHT_RING_TOE] = map.getValue(BodyPart.RIGHT_RING_TOE).copy(
rawRotation = Quaternion.fromRotationVector(24f, 54f, 29f),
rotation = Quaternion.fromRotationVector(24f, 54f, 29f),
isRotationActive = true,
)
}
@@ -315,15 +315,15 @@ class ToeDirectLinkProcessorTest {
skeletonHeight = 1.7f,
floorLevel = 0f,
paused = false,
pausedBoneInputs = inputs,
pausedProcessedBoneInputs = inputs,
)
val newInputs = processor.process(state.boneInputs, state.skeletonHeight)
val leftLittleToeIsSameRotationAsLeftRingToe =
newInputs[BodyPart.LEFT_LITTLE_TOE]?.rawRotation == newInputs[BodyPart.LEFT_RING_TOE]?.rawRotation
newInputs[BodyPart.LEFT_LITTLE_TOE]?.rotation == newInputs[BodyPart.LEFT_RING_TOE]?.rotation
val rightLittleToeIsSameRotationAsRightRingToe =
newInputs[BodyPart.RIGHT_LITTLE_TOE]?.rawRotation == newInputs[BodyPart.RIGHT_RING_TOE]?.rawRotation
newInputs[BodyPart.RIGHT_LITTLE_TOE]?.rotation == newInputs[BodyPart.RIGHT_RING_TOE]?.rotation
assertTrue(leftLittleToeIsSameRotationAsLeftRingToe && rightLittleToeIsSameRotationAsRightRingToe)
}
@@ -19,11 +19,14 @@ import kotlin.test.assertTrue
import kotlin.time.Duration.Companion.seconds
private fun bone(bodyPart: BodyPart, rotation: Quaternion = Quaternion.IDENTITY) = BoneState(
parentBone = null,
bodyPart = bodyPart,
offset = Vector3(0f, -0.1f, 0f),
rotation = rotation,
headPosition = Vector3(0f, 1f, 0f),
tailPosition = Vector3(0f, 0.9f, 0f),
angularVelocity = Vector3.NULL,
linearVelocity = Vector3.NULL,
)
private fun messages(bundle: OscBundle): List<OscMessage> = bundle.contents.map { (it as OscContent.Message).msg }