Toe tracking server rewrite (#1897)

Co-authored-by: Erimel <[email protected]>
Co-authored-by: Erimel <[email protected]>
Co-authored-by: loucass003 <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-09-01 06:20:44 +02:00
1 parent b8a72e43c0
commit e5ad3e02eb
23 files changed
+923 -73

No files matched your search

@@ -8,10 +8,27 @@ object ResetBodyParts {
BodyPart.RIGHT_UPPER_LEG,
)
val LEFT_TOES = setOf(
BodyPart.LEFT_BIG_TOE,
BodyPart.LEFT_INDEX_TOE,
BodyPart.LEFT_MIDDLE_TOE,
BodyPart.LEFT_RING_TOE,
BodyPart.LEFT_LITTLE_TOE,
)
val RIGHT_TOES = setOf(
BodyPart.RIGHT_BIG_TOE,
BodyPart.RIGHT_INDEX_TOE,
BodyPart.RIGHT_MIDDLE_TOE,
BodyPart.RIGHT_RING_TOE,
BodyPart.RIGHT_LITTLE_TOE,
)
val FEET = setOf(
BodyPart.LEFT_FOOT,
BodyPart.RIGHT_FOOT,
)
) +
LEFT_TOES +
RIGHT_TOES
val LEFT_FINGERS = setOf(
BodyPart.LEFT_THUMB_METACARPAL,
@@ -63,6 +63,22 @@ val BODY_PART_HIERARCHY_MAP: BodyPartMap<Array<BodyPart>> = BodyPartMap(
BodyPart.RIGHT_HIP to arrayOf(BodyPart.RIGHT_UPPER_LEG),
BodyPart.RIGHT_UPPER_LEG to arrayOf(BodyPart.RIGHT_LOWER_LEG),
BodyPart.RIGHT_LOWER_LEG to arrayOf(BodyPart.RIGHT_FOOT),
BodyPart.LEFT_FOOT to arrayOf(
BodyPart.LEFT_BIG_TOE,
BodyPart.LEFT_INDEX_TOE,
BodyPart.LEFT_MIDDLE_TOE,
BodyPart.LEFT_RING_TOE,
BodyPart.LEFT_LITTLE_TOE,
),
BodyPart.RIGHT_FOOT to arrayOf(
BodyPart.RIGHT_BIG_TOE,
BodyPart.RIGHT_INDEX_TOE,
BodyPart.RIGHT_MIDDLE_TOE,
BodyPart.RIGHT_RING_TOE,
BodyPart.RIGHT_LITTLE_TOE,
),
),
)
@@ -0,0 +1,44 @@
package dev.slimevr.skeleton.processors
import dev.slimevr.skeleton.BodyPartMap
import dev.slimevr.skeleton.InputSkeleton
import dev.slimevr.skeleton.SkeletonInputProcessor
import dev.slimevr.skeleton.SkeletonState
import dev.slimevr.skeleton.mutateCopy
import solarxr_protocol.datatypes.BodyPart
/**
* Handles rotations of inactive toe bones.
*/
class ToeDirectLinkInputProcessor : SkeletonInputProcessor {
/**
* First element is the linked BodyPart.
*
* Second element is the BodyPart the first element is linked to.
*/
private val toesToSource = arrayOf(
BodyPart.LEFT_BIG_TOE to BodyPart.LEFT_FOOT,
BodyPart.LEFT_INDEX_TOE to BodyPart.LEFT_BIG_TOE,
BodyPart.LEFT_MIDDLE_TOE to BodyPart.LEFT_INDEX_TOE,
BodyPart.LEFT_RING_TOE to BodyPart.LEFT_MIDDLE_TOE,
BodyPart.LEFT_LITTLE_TOE to BodyPart.LEFT_RING_TOE,
BodyPart.RIGHT_BIG_TOE to BodyPart.RIGHT_FOOT,
BodyPart.RIGHT_INDEX_TOE to BodyPart.RIGHT_BIG_TOE,
BodyPart.RIGHT_MIDDLE_TOE to BodyPart.RIGHT_INDEX_TOE,
BodyPart.RIGHT_RING_TOE to BodyPart.RIGHT_MIDDLE_TOE,
BodyPart.RIGHT_LITTLE_TOE to BodyPart.RIGHT_RING_TOE,
)
override fun process(inputSkeleton: InputSkeleton, skeletonHeight: Float): InputSkeleton {
return inputSkeleton.mutateCopy{ updated ->
for ((bodyPart, source) in toesToSource) {
val bone = updated.getValue(bodyPart)
if (bone.isRotationActive) continue
val sourceBone = updated[source]
updated[bodyPart] =
bone.copy(rawRotation = sourceBone?.rawRotation ?: bone.rawRotation)
}
}
}
}
@@ -17,6 +17,7 @@ import dev.slimevr.skeleton.inputprocessors.HeadPositionFallbackProcessor
import dev.slimevr.skeleton.inputprocessors.HipYawRollAlignInputProcessor
import dev.slimevr.skeleton.inputprocessors.SpineImputeInputProcessor
import dev.slimevr.skeleton.inputprocessors.UpperLegsRollAlignInputProcessor
import dev.slimevr.skeleton.processors.ToeDirectLinkInputProcessor
import io.github.axisangles.ktmath.Quaternion
import io.github.axisangles.ktmath.Vector3
import kotlinx.coroutines.CoroutineScope
@@ -188,6 +189,7 @@ class Skeleton(
UpperLegsRollAlignInputProcessor(settings),
BoneDirectLinkInputProcessor(),
FingerImputeInputProcessor(),
ToeDirectLinkInputProcessor(),
BonePredictionInputProcessor(settings),
BoneSmoothingInputProcessor(settings),
),
@@ -118,6 +118,8 @@ fun Map<SkeletonBone, Float>.toBoneOffsets(): BodyPartMap<Vector3> {
}
// Fingers
this[SkeletonBone.HAND_Y]?.let { offsets.putAll(getFingerOffsets(it)) }
// Toes
this[SkeletonBone.FOOT_LENGTH]?.let { offsets.putAll(getToeOffsets(it)) }
return offsets
}
@@ -206,3 +208,13 @@ private fun getFingerOffsets(handLength: Float) = (
private const val PROXIMAL_RATIO = 0.5f
private const val INTERMEDIATE_RATIO = 0.283f
private const val DISTAL_RATIO = 0.217f
/**
* Returns the offsets for the toe bones scaled from the handLength.
*/
private fun getToeOffsets(footLength: Float) = (
iterateBodyPartHierarchy(BodyPart.LEFT_FOOT, true) +
iterateBodyPartHierarchy(BodyPart.RIGHT_FOOT, true)
).map { it.second }.associateWith {
Vector3(0f, 0f, -footLength * 0.2f)
}
@@ -8,58 +8,68 @@ import io.github.axisangles.ktmath.Quaternion
import io.github.axisangles.ktmath.Vector3
import solarxr_protocol.datatypes.BodyPart
val BODY_PART_TO_UNITY_BONE: BodyPartMap<String> = BodyPartMap(
val BODY_PART_TO_UNITY_BONE: BodyPartMap<Array<String>> = BodyPartMap(
mapOf(
BodyPart.HEAD to "Head",
BodyPart.NECK to "Neck",
BodyPart.UPPER_CHEST to "UpperChest",
BodyPart.CHEST to "Chest",
BodyPart.WAIST to "Spine",
BodyPart.HIP to "Hips",
BodyPart.LEFT_SHOULDER to "LeftShoulder",
BodyPart.RIGHT_SHOULDER to "RightShoulder",
BodyPart.LEFT_UPPER_ARM to "LeftUpperArm",
BodyPart.RIGHT_UPPER_ARM to "RightUpperArm",
BodyPart.LEFT_LOWER_ARM to "LeftLowerArm",
BodyPart.RIGHT_LOWER_ARM to "RightLowerArm",
BodyPart.LEFT_HAND to "LeftHand",
BodyPart.RIGHT_HAND to "RightHand",
BodyPart.LEFT_UPPER_LEG to "LeftUpperLeg",
BodyPart.RIGHT_UPPER_LEG to "RightUpperLeg",
BodyPart.LEFT_LOWER_LEG to "LeftLowerLeg",
BodyPart.RIGHT_LOWER_LEG to "RightLowerLeg",
BodyPart.LEFT_FOOT to "LeftFoot",
BodyPart.RIGHT_FOOT to "RightFoot",
BodyPart.LEFT_THUMB_METACARPAL to "LeftThumbProximal",
BodyPart.LEFT_THUMB_PROXIMAL to "LeftThumbIntermediate",
BodyPart.LEFT_THUMB_DISTAL to "LeftThumbDistal",
BodyPart.LEFT_INDEX_PROXIMAL to "LeftIndexProximal",
BodyPart.LEFT_INDEX_INTERMEDIATE to "LeftIndexIntermediate",
BodyPart.LEFT_INDEX_DISTAL to "LeftIndexDistal",
BodyPart.LEFT_MIDDLE_PROXIMAL to "LeftMiddleProximal",
BodyPart.LEFT_MIDDLE_INTERMEDIATE to "LeftMiddleIntermediate",
BodyPart.LEFT_MIDDLE_DISTAL to "LeftMiddleDistal",
BodyPart.LEFT_RING_PROXIMAL to "LeftRingProximal",
BodyPart.LEFT_RING_INTERMEDIATE to "LeftRingIntermediate",
BodyPart.LEFT_RING_DISTAL to "LeftRingDistal",
BodyPart.LEFT_LITTLE_PROXIMAL to "LeftLittleProximal",
BodyPart.LEFT_LITTLE_INTERMEDIATE to "LeftLittleIntermediate",
BodyPart.LEFT_LITTLE_DISTAL to "LeftLittleDistal",
BodyPart.RIGHT_THUMB_METACARPAL to "RightThumbProximal",
BodyPart.RIGHT_THUMB_PROXIMAL to "RightThumbIntermediate",
BodyPart.RIGHT_THUMB_DISTAL to "RightThumbDistal",
BodyPart.RIGHT_INDEX_PROXIMAL to "RightIndexProximal",
BodyPart.RIGHT_INDEX_INTERMEDIATE to "RightIndexIntermediate",
BodyPart.RIGHT_INDEX_DISTAL to "RightIndexDistal",
BodyPart.RIGHT_MIDDLE_PROXIMAL to "RightMiddleProximal",
BodyPart.RIGHT_MIDDLE_INTERMEDIATE to "RightMiddleIntermediate",
BodyPart.RIGHT_MIDDLE_DISTAL to "RightMiddleDistal",
BodyPart.RIGHT_RING_PROXIMAL to "RightRingProximal",
BodyPart.RIGHT_RING_INTERMEDIATE to "RightRingIntermediate",
BodyPart.RIGHT_RING_DISTAL to "RightRingDistal",
BodyPart.RIGHT_LITTLE_PROXIMAL to "RightLittleProximal",
BodyPart.RIGHT_LITTLE_INTERMEDIATE to "RightLittleIntermediate",
BodyPart.RIGHT_LITTLE_DISTAL to "RightLittleDistal",
BodyPart.HEAD to arrayOf("Head"),
BodyPart.NECK to arrayOf("Neck"),
BodyPart.UPPER_CHEST to arrayOf("UpperChest"),
BodyPart.CHEST to arrayOf("Chest"),
BodyPart.WAIST to arrayOf("Spine"),
BodyPart.HIP to arrayOf("Hips"),
BodyPart.LEFT_SHOULDER to arrayOf("LeftShoulder"),
BodyPart.RIGHT_SHOULDER to arrayOf("RightShoulder"),
BodyPart.LEFT_UPPER_ARM to arrayOf("LeftUpperArm"),
BodyPart.RIGHT_UPPER_ARM to arrayOf("RightUpperArm"),
BodyPart.LEFT_LOWER_ARM to arrayOf("LeftLowerArm"),
BodyPart.RIGHT_LOWER_ARM to arrayOf("RightLowerArm"),
BodyPart.LEFT_HAND to arrayOf("LeftHand"),
BodyPart.RIGHT_HAND to arrayOf("RightHand"),
BodyPart.LEFT_UPPER_LEG to arrayOf("LeftUpperLeg"),
BodyPart.RIGHT_UPPER_LEG to arrayOf("RightUpperLeg"),
BodyPart.LEFT_LOWER_LEG to arrayOf("LeftLowerLeg"),
BodyPart.RIGHT_LOWER_LEG to arrayOf("RightLowerLeg"),
BodyPart.LEFT_FOOT to arrayOf("LeftFoot"),
BodyPart.RIGHT_FOOT to arrayOf("RightFoot"),
BodyPart.LEFT_THUMB_METACARPAL to arrayOf("LeftThumbProximal"),
BodyPart.LEFT_THUMB_PROXIMAL to arrayOf("LeftThumbIntermediate"),
BodyPart.LEFT_THUMB_DISTAL to arrayOf("LeftThumbDistal"),
BodyPart.LEFT_INDEX_PROXIMAL to arrayOf("LeftIndexProximal"),
BodyPart.LEFT_INDEX_INTERMEDIATE to arrayOf("LeftIndexIntermediate"),
BodyPart.LEFT_INDEX_DISTAL to arrayOf("LeftIndexDistal"),
BodyPart.LEFT_MIDDLE_PROXIMAL to arrayOf("LeftMiddleProximal"),
BodyPart.LEFT_MIDDLE_INTERMEDIATE to arrayOf("LeftMiddleIntermediate"),
BodyPart.LEFT_MIDDLE_DISTAL to arrayOf("LeftMiddleDistal"),
BodyPart.LEFT_RING_PROXIMAL to arrayOf("LeftRingProximal"),
BodyPart.LEFT_RING_INTERMEDIATE to arrayOf("LeftRingIntermediate"),
BodyPart.LEFT_RING_DISTAL to arrayOf("LeftRingDistal"),
BodyPart.LEFT_LITTLE_PROXIMAL to arrayOf("LeftLittleProximal"),
BodyPart.LEFT_LITTLE_INTERMEDIATE to arrayOf("LeftLittleIntermediate"),
BodyPart.LEFT_LITTLE_DISTAL to arrayOf("LeftLittleDistal"),
BodyPart.RIGHT_THUMB_METACARPAL to arrayOf("RightThumbProximal"),
BodyPart.RIGHT_THUMB_PROXIMAL to arrayOf("RightThumbIntermediate"),
BodyPart.RIGHT_THUMB_DISTAL to arrayOf("RightThumbDistal"),
BodyPart.RIGHT_INDEX_PROXIMAL to arrayOf("RightIndexProximal"),
BodyPart.RIGHT_INDEX_INTERMEDIATE to arrayOf("RightIndexIntermediate"),
BodyPart.RIGHT_INDEX_DISTAL to arrayOf("RightIndexDistal"),
BodyPart.RIGHT_MIDDLE_PROXIMAL to arrayOf("RightMiddleProximal"),
BodyPart.RIGHT_MIDDLE_INTERMEDIATE to arrayOf("RightMiddleIntermediate"),
BodyPart.RIGHT_MIDDLE_DISTAL to arrayOf("RightMiddleDistal"),
BodyPart.RIGHT_RING_PROXIMAL to arrayOf("RightRingProximal"),
BodyPart.RIGHT_RING_INTERMEDIATE to arrayOf("RightRingIntermediate"),
BodyPart.RIGHT_RING_DISTAL to arrayOf("RightRingDistal"),
BodyPart.RIGHT_LITTLE_PROXIMAL to arrayOf("RightLittleProximal"),
BodyPart.RIGHT_LITTLE_INTERMEDIATE to arrayOf("RightLittleIntermediate"),
BodyPart.RIGHT_LITTLE_DISTAL to arrayOf("RightLittleDistal"),
BodyPart.LEFT_BIG_TOE to arrayOf("LeftToes", "LeftBigToe"),
BodyPart.LEFT_INDEX_TOE to arrayOf("LeftIndexToe"),
BodyPart.LEFT_MIDDLE_TOE to arrayOf("LeftMiddleToe"),
BodyPart.LEFT_RING_TOE to arrayOf("LeftRingToe"),
BodyPart.LEFT_LITTLE_TOE to arrayOf("LeftLittleToe"),
BodyPart.RIGHT_BIG_TOE to arrayOf("RightToes", "RightBigToe"),
BodyPart.RIGHT_INDEX_TOE to arrayOf("RightIndexToe"),
BodyPart.RIGHT_MIDDLE_TOE to arrayOf("RightMiddleToe"),
BodyPart.RIGHT_RING_TOE to arrayOf("RightRingToe"),
BodyPart.RIGHT_LITTLE_TOE to arrayOf("RightLittleToe"),
),
)
@@ -119,6 +129,20 @@ val VMC_HIERARCHY_MAP: BodyPartMap<Array<BodyPart>> = BodyPartMap(
BodyPart.RIGHT_RING_INTERMEDIATE to arrayOf(BodyPart.RIGHT_RING_DISTAL),
BodyPart.RIGHT_LITTLE_PROXIMAL to arrayOf(BodyPart.RIGHT_LITTLE_INTERMEDIATE),
BodyPart.RIGHT_LITTLE_INTERMEDIATE to arrayOf(BodyPart.RIGHT_LITTLE_DISTAL),
BodyPart.LEFT_FOOT to arrayOf(
BodyPart.LEFT_BIG_TOE,
BodyPart.LEFT_INDEX_TOE,
BodyPart.LEFT_MIDDLE_TOE,
BodyPart.LEFT_RING_TOE,
BodyPart.LEFT_LITTLE_TOE,
),
BodyPart.RIGHT_FOOT to arrayOf(
BodyPart.RIGHT_BIG_TOE,
BodyPart.RIGHT_INDEX_TOE,
BodyPart.RIGHT_MIDDLE_TOE,
BodyPart.RIGHT_RING_TOE,
BodyPart.RIGHT_LITTLE_TOE,
),
),
)
@@ -155,6 +179,12 @@ val VMC_MIRROR_BONE_PAIRS: List<Pair<BodyPart, BodyPart>> = listOf(
BodyPart.LEFT_LITTLE_PROXIMAL to BodyPart.RIGHT_LITTLE_PROXIMAL,
BodyPart.LEFT_LITTLE_INTERMEDIATE to BodyPart.RIGHT_LITTLE_INTERMEDIATE,
BodyPart.LEFT_LITTLE_DISTAL to BodyPart.RIGHT_LITTLE_DISTAL,
BodyPart.LEFT_BIG_TOE to BodyPart.RIGHT_BIG_TOE,
BodyPart.LEFT_BIG_TOE to BodyPart.RIGHT_BIG_TOE,
BodyPart.LEFT_INDEX_TOE to BodyPart.RIGHT_INDEX_TOE,
BodyPart.LEFT_MIDDLE_TOE to BodyPart.RIGHT_MIDDLE_TOE,
BodyPart.LEFT_RING_TOE to BodyPart.RIGHT_RING_TOE,
BodyPart.LEFT_LITTLE_TOE to BodyPart.RIGHT_LITTLE_TOE,
)
val VMC_MIRROR_BONES: BodyPartMap<BodyPart> = BodyPartMap(
@@ -27,7 +27,7 @@ internal fun buildOutgoingBundle(
add(OscContent.Message(transformMessage("/VMC/Ext/Root/Pos", "root", Vector3.NULL, Quaternion.IDENTITY)))
// TODO UpperChest + shoulders affecting arms local rot
for ((targetBodyPart, unityName) in BODY_PART_TO_UNITY_BONE) {
for ((targetBodyPart, unityNames) in BODY_PART_TO_UNITY_BONE) {
if (targetBodyPart !in routedBones) continue
val targetParentBodyPart = VMC_BONE_PARENTS[targetBodyPart]
@@ -38,7 +38,7 @@ internal fun buildOutgoingBundle(
// TODO anchorHip https://github.com/SlimeVR/SlimeVR-Server/blob/main/server/core/src/main/java/dev/slimevr/osc/VMCHandler.kt#L371
val pos = vrm?.hipLocalPosition ?: Vector3.NULL
val rot = vmcLocalRotation(trackingBone, null, targetBodyPart, null, config.mirrorTracking)
add(OscContent.Message(transformMessage("/VMC/Ext/Bone/Pos", unityName, pos, rot)))
add(OscContent.Message(transformMessage("/VMC/Ext/Bone/Pos", unityNames.first(), pos, rot)))
continue
}
@@ -61,7 +61,9 @@ internal fun buildOutgoingBundle(
targetParentBodyPart,
config.mirrorTracking,
)
add(OscContent.Message(transformMessage("/VMC/Ext/Bone/Pos", unityName, pos, rot)))
for (outputName in unityNames) {
add(OscContent.Message(transformMessage("/VMC/Ext/Bone/Pos", outputName, pos, rot)))
}
}
}
@@ -91,7 +91,7 @@ data class VrmGeometry(
fun buildVrmGeometry(reader: VrmReader): VrmGeometry {
val bindOffsets = BodyPartMap(
BODY_PART_TO_UNITY_BONE.mapValues { (_, unityName) -> reader.offsetForBone(unityName) ?: Vector3.NULL },
BODY_PART_TO_UNITY_BONE.mapValues { (_, unityNames) -> reader.offsetForBone(unityNames.first()) ?: Vector3.NULL },
)
fun offset(bodyPart: BodyPart) = bindOffsets[bodyPart] ?: Vector3.NULL
@@ -30,7 +30,7 @@ internal fun buildOutgoingBundle(
bones: ComputedSkeleton,
routedBones: Set<BodyPart>,
): OscBundle? {
val messages = buildList {
val messages = buildList<OscContent> {
for ((bodyPart, trackerId) in trackerIdsByBodyPart) {
if (bodyPart !in routedBones) continue
@@ -54,6 +54,8 @@ internal fun buildOutgoingBundle(
),
)
}
addAll(buildToeMessages(bones))
}
return messages.takeIf { it.isNotEmpty() }?.let { OscBundle(1L, it) }
@@ -0,0 +1,113 @@
package dev.slimevr.vrcosc
import dev.slimevr.osc.OscArg
import dev.slimevr.osc.OscContent
import dev.slimevr.osc.OscMessage
import dev.slimevr.skeleton.BoneState
import dev.slimevr.util.Side
import dev.slimevr.util.opposite
import io.github.axisangles.ktmath.EulerOrder
import io.github.axisangles.ktmath.Quaternion
import io.github.axisangles.ktmath.Vector3
import solarxr_protocol.datatypes.BodyPart
import kotlin.math.*
private const val ABSOLUTE_SPLAY_THRESHOLD_ANGLE = 7
private const val MINIMUM_TIP_TOE_PITCH = -14
private const val MINIMUM_BENDING_PITCH = 15
private const val MAXIMUM_ABSOLUTE_TOE_RANGE = 90
internal fun buildToeMessages(bones: Map<BodyPart, BoneState>): List<OscContent> {
val messages = mutableListOf<OscContent>()
// LEFT FOOT + TOES
val leftFoot = bones[BodyPart.LEFT_FOOT]
if (leftFoot != null) {
val leftToes = listOf(
bones[BodyPart.LEFT_BIG_TOE],
bones[BodyPart.LEFT_INDEX_TOE],
bones[BodyPart.LEFT_MIDDLE_TOE],
bones[BodyPart.LEFT_RING_TOE],
bones[BodyPart.LEFT_LITTLE_TOE],
)
processToesForFoot(leftFoot, leftToes, Side.LEFT, messages)
}
// RIGHT FOOT + TOES
val rightFoot = bones[BodyPart.RIGHT_FOOT]
if (rightFoot != null) {
val rightToes = listOf(
bones[BodyPart.RIGHT_BIG_TOE],
bones[BodyPart.RIGHT_INDEX_TOE],
bones[BodyPart.RIGHT_MIDDLE_TOE],
bones[BodyPart.RIGHT_RING_TOE],
bones[BodyPart.RIGHT_LITTLE_TOE],
)
processToesForFoot(rightFoot, rightToes, Side.RIGHT, messages)
}
return messages
}
private fun processToesForFoot(
foot: BoneState,
toeBones: List<BoneState?>,
side: Side,
messages: MutableList<OscContent>,
) {
var lastAssigned: BoneState? = null
for ((segmentIndex, toe) in toeBones.withIndex()) {
if (toe != null) {
lastAssigned = toe
}
if (lastAssigned == null) continue
val splayDirection = if (segmentIndex > 0) side else side.opposite
processToe(foot, lastAssigned, side, segmentIndex, splayDirection, messages)
}
}
private val Side.oscName: String
get() = when (this) {
Side.LEFT -> "Left"
Side.RIGHT -> "Right"
}
private fun processToe(
foot: BoneState,
toe: BoneState,
side: Side,
toeNumber: Int,
splayDirection: Side,
messages: MutableList<OscContent>,
) {
val oscToeNumber = toeNumber + 1
val footRot = foot.rotation
val toeRot = toe.rotation
val currentRelative = footRot.inv() * toeRot
val euler = currentRelative.toEulerAngles(EulerOrder.XYZ)
val pitch = Math.toDegrees(euler.x.toDouble()).toFloat()
val yaw = Math.toDegrees(euler.z.toDouble()).toFloat()
val tipToe = pitch < MINIMUM_TIP_TOE_PITCH
val bending = pitch > MINIMUM_BENDING_PITCH
val splayed = when (splayDirection) {
Side.LEFT -> yaw < -ABSOLUTE_SPLAY_THRESHOLD_ANGLE
Side.RIGHT -> yaw > ABSOLUTE_SPLAY_THRESHOLD_ANGLE
}
val toeCurlValue = (pitch / MAXIMUM_ABSOLUTE_TOE_RANGE).coerceIn(-1f, 1f)
val toeSplayValue = (yaw / MAXIMUM_ABSOLUTE_TOE_RANGE).coerceIn(-1f, 1f)
messages.addAll(
listOf(
OscContent.Message(OscMessage("/avatar/parameters/TipToes${side.oscName}", listOf(if (tipToe) OscArg.True else OscArg.False))),
OscContent.Message(OscMessage("/avatar/parameters/ToeBent${side.oscName}${oscToeNumber}Bool", listOf(if (bending) OscArg.True else OscArg.False))),
OscContent.Message(OscMessage("/avatar/parameters/ToeSplay${side.oscName}$oscToeNumber", listOf(if (splayed) OscArg.True else OscArg.False))),
OscContent.Message(OscMessage("/avatar/parameters/Toe${side.oscName}${oscToeNumber}Float", listOf(OscArg.Float(toeCurlValue)))),
OscContent.Message(OscMessage("/avatar/parameters/ToeSplay${side.oscName}${oscToeNumber}Float", listOf(OscArg.Float(toeSplayValue)))),
),
)
}