Run neck processor even without active head

This commit is contained in:
Erimel committed 2026-10-15 17:22:39 -04:00
1 parent e977e5dd0e
commit 13bb66c9e0
2 files changed
+7 -7

No files matched your search

@@ -115,7 +115,7 @@ fun ccdIk(
threshold: Float,
maxIterations: Int,
): IKOutput {
// No goals leaves every bone as the FK pass built it, so nothing below needs to run
// No goal leaves every bone as the FK pass built it, so nothing below needs to run
if (goals.isEmpty()) return IKOutput(bones, emptyMap())
val workingBoneInputs = EnumMap(boneInputs)
@@ -14,17 +14,17 @@ private const val DOWN_RATIO = 1.1f
* Guesses where the neck is supposed to be when the user has a head tracker but no neck tracker.
*
* Tries to mitigate the problem where looking down make your whole tracking go down (or
* knees bend if floorclip is enabled).
* knees bend if floor-clip is enabled).
*/
class NeckInputProcessor : SkeletonInputProcessor {
override fun process(mutableInputSkeleton: InputSkeleton, skeletonHeight: Float) {
val headBone = mutableInputSkeleton[BodyPart.HEAD] ?: return
val neckBone = mutableInputSkeleton[BodyPart.NECK] ?: return
val upperChestBone = mutableInputSkeleton[BodyPart.UPPER_CHEST] ?: return
if (!headBone.isRotationActive || neckBone.isRotationActive) return
if (neckBone.isRotationActive) return
val upperChestRotation = mutableInputSkeleton[BodyPart.UPPER_CHEST]?.rotation ?: return
val headRotation = mutableInputSkeleton[BodyPart.HEAD]?.rotation ?: return
// Work with the rotation delta to avoid axes being ambiguous
val delta = upperChestBone.rotation.inv() * headBone.rotation
val delta = upperChestRotation.inv() * headRotation
// Decompose the delta into its twist (forward) and swing (remaining/sides) along the x-axis
val forward = delta.project(Vector3.POS_X).unit()
@@ -34,7 +34,7 @@ class NeckInputProcessor : SkeletonInputProcessor {
val ratio = if (forward.x < 0f) DOWN_RATIO else UP_RATIO
val scaledDelta = side * forward.pow(ratio)
val newRotation = upperChestBone.rotation * scaledDelta
val newRotation = upperChestRotation * scaledDelta
mutableInputSkeleton[BodyPart.NECK] = neckBone.copy(rotation = newRotation)
}
}