mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-12-06 08:42:32 -08:00
Constrain preferred rotations
This commit is contained in:
1 parent
4e84ebdfc9
commit
4e5f0736d9
2 files changed
+16
-9
No files matched your search
@@ -113,7 +113,7 @@ val BODY_PART_CONSTRAINT_MAP: BodyPartMap<Constraint> = BodyPartMap(
|
||||
90f * FastMath.DEG_TO_RAD,
|
||||
),
|
||||
BodyPart.LEFT_LOWER_LEG to LooseHingeConstraint(
|
||||
-150f * FastMath.DEG_TO_RAD,
|
||||
-165f * FastMath.DEG_TO_RAD,
|
||||
6f * FastMath.DEG_TO_RAD,
|
||||
65f * FastMath.DEG_TO_RAD,
|
||||
),
|
||||
@@ -130,7 +130,7 @@ val BODY_PART_CONSTRAINT_MAP: BodyPartMap<Constraint> = BodyPartMap(
|
||||
90f * FastMath.DEG_TO_RAD,
|
||||
),
|
||||
BodyPart.RIGHT_LOWER_LEG to LooseHingeConstraint(
|
||||
-150f * FastMath.DEG_TO_RAD,
|
||||
-165f * FastMath.DEG_TO_RAD,
|
||||
6f * FastMath.DEG_TO_RAD,
|
||||
65f * FastMath.DEG_TO_RAD,
|
||||
),
|
||||
@@ -219,10 +219,10 @@ val BODY_PART_PREFERRED_ROTATION = BodyPartMap(
|
||||
BodyPart.LEFT_LOWER_ARM to Quaternion.fromRotationVector(0f, 70f * FastMath.DEG_TO_RAD, 0f),
|
||||
BodyPart.RIGHT_LOWER_ARM to Quaternion.fromRotationVector(0f, -70f * FastMath.DEG_TO_RAD, 0f),
|
||||
|
||||
BodyPart.LEFT_UPPER_LEG to Quaternion.rotationAroundXAxis(115f * FastMath.DEG_TO_RAD),
|
||||
BodyPart.RIGHT_UPPER_LEG to Quaternion.rotationAroundXAxis(115f * FastMath.DEG_TO_RAD),
|
||||
BodyPart.LEFT_LOWER_LEG to Quaternion.rotationAroundXAxis(-48f * FastMath.DEG_TO_RAD),
|
||||
BodyPart.RIGHT_LOWER_LEG to Quaternion.rotationAroundXAxis(-48f * FastMath.DEG_TO_RAD),
|
||||
BodyPart.LEFT_UPPER_LEG to Quaternion.rotationAroundXAxis(35f * FastMath.DEG_TO_RAD),
|
||||
BodyPart.RIGHT_UPPER_LEG to Quaternion.rotationAroundXAxis(35f * FastMath.DEG_TO_RAD),
|
||||
BodyPart.LEFT_LOWER_LEG to Quaternion.rotationAroundXAxis(-20f * FastMath.DEG_TO_RAD),
|
||||
BodyPart.RIGHT_LOWER_LEG to Quaternion.rotationAroundXAxis(-20f * FastMath.DEG_TO_RAD),
|
||||
|
||||
// BodyPart.UPPER_CHEST to Quaternion.rotationAroundXAxis(-10f * FastMath.DEG_TO_RAD),
|
||||
// BodyPart.LOWER_CHEST to Quaternion.rotationAroundXAxis(-5f * FastMath.DEG_TO_RAD),
|
||||
|
||||
@@ -32,12 +32,13 @@ fun parentRot(
|
||||
bones[parent]?.rotation
|
||||
} ?: Quaternion.IDENTITY
|
||||
|
||||
const val PREFERRED_ROTATION_START_BIAS = 25.0
|
||||
const val PREFERRED_ROTATION_START_BIAS = 62.0
|
||||
const val PREFERRED_ROTATION_START_BIAS_MULTIPLIER = (PREFERRED_ROTATION_START_BIAS * PREFERRED_ROTATION_START_BIAS) - PREFERRED_ROTATION_START_BIAS
|
||||
fun adjustToPreferredRotations(
|
||||
mutableBoneInputs: InputSkeleton,
|
||||
mutableComputedSkeleton: ComputedSkeleton,
|
||||
goals: List<IKChainGoal>,
|
||||
constraints: BodyPartMap<Constraint>?,
|
||||
) {
|
||||
val changedBodyParts = mutableSetOf<BodyPart>()
|
||||
for (goal in goals) {
|
||||
@@ -48,7 +49,13 @@ fun adjustToPreferredRotations(
|
||||
for (bodyPart in goal.chain) {
|
||||
val preferredRotation = BODY_PART_PREFERRED_ROTATION[bodyPart] ?: continue
|
||||
val bone = mutableBoneInputs[bodyPart] ?: continue
|
||||
mutableBoneInputs[bodyPart] = bone.copy(rotation = bone.rotation * preferredRotation.pow(t))
|
||||
val offsetRotation = bone.rotation * preferredRotation.pow(t)
|
||||
val newRotation = constraints?.get(bodyPart)?.apply(
|
||||
parentRot(mutableComputedSkeleton, bodyPart),
|
||||
offsetRotation,
|
||||
) ?: offsetRotation
|
||||
|
||||
mutableBoneInputs[bodyPart] = bone.copy(rotation = newRotation)
|
||||
changedBodyParts.add(bodyPart)
|
||||
}
|
||||
}
|
||||
@@ -200,7 +207,7 @@ fun ccdIk(
|
||||
if (goals.isEmpty()) return true
|
||||
|
||||
// Set each bone we're gonna do IK on to its preferred rotation
|
||||
adjustToPreferredRotations(mutableBoneInputs, mutableComputedSkeleton, goals)
|
||||
adjustToPreferredRotations(mutableBoneInputs, mutableComputedSkeleton, goals, constraints)
|
||||
|
||||
// IK iterations
|
||||
var allGoalsMet = true
|
||||
|
||||
Reference in new issue
Block a user