From 456e09c1ed3fbe87053446745a62b34bfa3fef24 Mon Sep 17 00:00:00 2001 From: Butterscotch! Date: Thu, 5 Nov 2026 22:53:34 -0500 Subject: [PATCH] Improve arm IK consistency --- .../slimevr/skeleton/bodypart-constraints.kt | 26 +++++++++++++++---- .../java/dev/slimevr/skeleton/constraint.kt | 3 ++- .../src/main/java/dev/slimevr/skeleton/ik.kt | 2 ++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/server/core/src/main/java/dev/slimevr/skeleton/bodypart-constraints.kt b/server/core/src/main/java/dev/slimevr/skeleton/bodypart-constraints.kt index d59f4f4b8..d924a06be 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/bodypart-constraints.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/bodypart-constraints.kt @@ -2,6 +2,7 @@ package dev.slimevr.skeleton import com.jme3.math.FastMath import io.github.axisangles.ktmath.Quaternion +import io.github.axisangles.ktmath.Vector3 import solarxr_protocol.datatypes.BodyPart // For fingers and toes @@ -183,11 +184,26 @@ fun constrainSkeleton( val BODY_PART_OFFSET_CONSTRAINT_MAP: BodyPartMap = BodyPartMap( mapOf( // TODO Figure out arms - // BodyPart.LEFT_UPPER_ARM to AxisConstraint(), - // BodyPart.RIGHT_UPPER_ARM to AxisConstraint(), + BodyPart.LEFT_UPPER_ARM to TwistSwingConstraint( + 5f * FastMath.DEG_TO_RAD, + 30f * FastMath.DEG_TO_RAD, + Vector3.NEG_X, + ), + BodyPart.LEFT_LOWER_ARM to LooseAxisConstraint( + 1f * FastMath.DEG_TO_RAD, + ), + + BodyPart.RIGHT_UPPER_ARM to TwistSwingConstraint( + 5f * FastMath.DEG_TO_RAD, + 30f * FastMath.DEG_TO_RAD, + Vector3.NEG_X, + ), + BodyPart.RIGHT_LOWER_ARM to LooseAxisConstraint( + 1f * FastMath.DEG_TO_RAD, + ), BodyPart.UPPER_CHEST to LooseAxisConstraint( - 10f * FastMath.DEG_TO_RAD, + 15f * FastMath.DEG_TO_RAD, ), BodyPart.LOWER_CHEST to LooseAxisConstraint( 10f * FastMath.DEG_TO_RAD, @@ -203,14 +219,14 @@ val BODY_PART_OFFSET_CONSTRAINT_MAP: BodyPartMap = BodyPartMap( 5f * FastMath.DEG_TO_RAD, ), BodyPart.LEFT_LOWER_LEG to LooseAxisConstraint( - 0.1f * FastMath.DEG_TO_RAD, + 1f * FastMath.DEG_TO_RAD, ), BodyPart.RIGHT_UPPER_LEG to LooseAxisConstraint( 5f * FastMath.DEG_TO_RAD, ), BodyPart.RIGHT_LOWER_LEG to LooseAxisConstraint( - 0.1f * FastMath.DEG_TO_RAD, + 1f * FastMath.DEG_TO_RAD, ), ), ) diff --git a/server/core/src/main/java/dev/slimevr/skeleton/constraint.kt b/server/core/src/main/java/dev/slimevr/skeleton/constraint.kt index eb161866f..cc4f39da1 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/constraint.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/constraint.kt @@ -41,9 +41,10 @@ data class TwistSwingConstraint( * Swing range in radians. */ val swing: Float, + val twistAxis: Vector3 = Vector3.NEG_Y, ) : Constraint { override fun apply(localRotation: Quaternion): Quaternion { - var (swingQ, twistQ) = decomposeToSwingTwist(localRotation, Vector3.NEG_Y) + var (swingQ, twistQ) = decomposeToSwingTwist(localRotation, twistAxis) swingQ = constrainAngle(swingQ, swing) twistQ = constrainAngle(twistQ, twist) return swingQ * twistQ diff --git a/server/core/src/main/java/dev/slimevr/skeleton/ik.kt b/server/core/src/main/java/dev/slimevr/skeleton/ik.kt index 1bfdf49dd..af9f085b0 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/ik.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/ik.kt @@ -155,6 +155,8 @@ fun ccdIkIteration( rotateChain(mutableBoneInputs, chain, constrainedOffset) // Only build bones for inputs that were changed + // If performance is bad, we can combine buildBones calls for non-overlapping IK + // chains buildBones(mutableComputedSkeleton, mutableBoneInputs, chain.toSet()) }