Improve arm IK consistency

This commit is contained in:
Butterscotch! committed 2026-11-05 22:53:34 -05:00
1 parent ab82ce59e7
commit 456e09c1ed
3 files changed
+25 -6

No files matched your search

@@ -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<Constraint> = 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<Constraint> = 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,
),
),
)
@@ -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
@@ -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())
}