From 4b02f8d81b5069a14bce8d5074a1efdcf9a1357f Mon Sep 17 00:00:00 2001 From: Erimel Date: Wed, 14 Oct 2026 14:48:18 -0400 Subject: [PATCH] Fix and improve toe snap --- gui/app/src/utils/skeletonParts.ts | 2 +- .../skeleton/fkprocessors/foot-plant.kt | 4 +- .../slimevr/skeleton/fkprocessors/toe-snap.kt | 37 +++++++++---------- .../java/dev/slimevr/skeleton/proportions.kt | 2 +- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/gui/app/src/utils/skeletonParts.ts b/gui/app/src/utils/skeletonParts.ts index c5de2c372..590546dc0 100644 --- a/gui/app/src/utils/skeletonParts.ts +++ b/gui/app/src/utils/skeletonParts.ts @@ -247,7 +247,7 @@ const lowerLegScale = spanBone({ girthFrom: 'hips', length: 0.78 }); const footScale: ShapeScale = { compute: ({ boneLength }) => { const ratio = boneLength / RIG_FOOT_LENGTH; - return { width: 0.9 * ratio, length: 1.12 * ratio, depth: 1.14 * ratio }; + return { width: 0.9 * ratio, length: 1.12 * ratio, depth: 1.14 }; }, }; // Forward follows foot length; the drop from the ankle to the sole doesn't. diff --git a/server/core/src/main/java/dev/slimevr/skeleton/fkprocessors/foot-plant.kt b/server/core/src/main/java/dev/slimevr/skeleton/fkprocessors/foot-plant.kt index 4ddb94671..f63bbde5a 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/fkprocessors/foot-plant.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/fkprocessors/foot-plant.kt @@ -12,9 +12,9 @@ const val ROTATION_CORRECTION_VERTICAL = 0.1f fun computeFootPlantRatio( ankleHeight: Float, - floorHeight: Float, + floorLevel: Float, ): Float { - val ankleHeightAboveFloor = ankleHeight - floorHeight + val ankleHeightAboveFloor = ankleHeight - floorLevel val ratioOfRangeFromFloor = (ankleHeightAboveFloor / ROTATION_CORRECTION_VERTICAL).coerceIn(0f, 1f) // Ratio of range *to* floor return 1f - ratioOfRangeFromFloor diff --git a/server/core/src/main/java/dev/slimevr/skeleton/fkprocessors/toe-snap.kt b/server/core/src/main/java/dev/slimevr/skeleton/fkprocessors/toe-snap.kt index 153cc36d5..0b26fdebd 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/fkprocessors/toe-snap.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/fkprocessors/toe-snap.kt @@ -9,49 +9,46 @@ import io.github.axisangles.ktmath.Quaternion import io.github.axisangles.ktmath.Vector3 import solarxr_protocol.datatypes.BodyPart import kotlin.math.abs -import kotlin.math.asin -const val TOE_SNAP_RANGE_MULTIPLE = 2f -const val MAX_TOE_SNAP_ANGLE = -0.8f +const val TOE_SNAP_RANGE_MULTIPLIER = 2f +const val MAX_TOE_SNAP_RATIO = 0.8f const val ANKLE_DOWN_MIN = 0.65f const val ANKLE_DOWN_MAX = 0.85f fun computeToeSnapRatio( - ankleLocalPosition: Vector3, ankleHeight: Float, footLength: Float, - floorHeight: Float, + floorLevel: Float, + ankleLocalPosition: Vector3, ): Float { - val ankleHeightAboveFloor = ankleHeight - floorHeight - // Toe height if the foot is pointing directly down to the floor + val ankleHeightAboveFloor = ankleHeight - floorLevel + + // Compute the floor to floor ratio. 0 = heel is touching floor, 1 = tip of foot is touching floor + val footToFloorRatio = ankleHeightAboveFloor.coerceIn(0f, footLength) / footLength + + // Compute the range over which the toes can snap to the floor val potentialToeHeightAboveFloor = ankleHeightAboveFloor - footLength - // The range over which the toes snap to the floor - val toeSnapRange = footLength * TOE_SNAP_RANGE_MULTIPLE + val toeSnapRange = footLength * TOE_SNAP_RANGE_MULTIPLIER val ratioOfRangeFromFloor = (potentialToeHeightAboveFloor / toeSnapRange).coerceIn(0f, 1f) - // Reduce the range back down as we touch the floor - val footAngleToFloor = asin(ankleHeightAboveFloor.coerceIn(0f, footLength) / footLength) - val ratioOfMaxAngleToFloor = abs(footAngleToFloor * MAX_TOE_SNAP_ANGLE).coerceIn(0f, 1f) - // Ratio of range *to* floor - val rangeToFloorRatio = (1f - ratioOfRangeFromFloor) * ratioOfMaxAngleToFloor + val rangeToFloorRatio = (1f - ratioOfRangeFromFloor) * footToFloorRatio - // Lessen the ratio with the ankle pointing forward. + // Lessen the ratio as the ankle doesn't point down val ankleDownDirection = abs(ankleLocalPosition.unit().y.coerceAtMost(0f)) val ankleDownRatio = FastMath.clampedRemap(ankleDownDirection, ANKLE_DOWN_MIN, ANKLE_DOWN_MAX, 0f, 1f) return rangeToFloorRatio * ankleDownRatio } +private val MAX_TOE_SNAP_PITCH = Quaternion.rotationAroundXAxis(-MAX_TOE_SNAP_RATIO) fun snapToes( rotation: Quaternion, correctionRatio: Float, ): Quaternion { - val heading = rotation.eulerHeading() - val maxPitch = Quaternion.rotationAroundXAxis(MAX_TOE_SNAP_ANGLE * correctionRatio) // Pitch must be applied first - val maxCorrection = heading * maxPitch - return rotation.interpQ(maxCorrection, correctionRatio) + val maxCorrected = rotation.eulerHeading() * MAX_TOE_SNAP_PITCH + return rotation.interpQ(maxCorrected, correctionRatio) } class ToeSnapFkProcessor(val skeleton: Skeleton) : SkeletonFkProcessor { @@ -74,10 +71,10 @@ class ToeSnapFkProcessor(val skeleton: Skeleton) : SkeletonFkProcessor { rotation = snapToes( input.rotation, computeToeSnapRatio( - ankle.localTailPosition, foot.headPosition.y, length, floorLevel, + ankle.localTailPosition, ), ), ) diff --git a/server/core/src/main/java/dev/slimevr/skeleton/proportions.kt b/server/core/src/main/java/dev/slimevr/skeleton/proportions.kt index 28de491be..a9119e7e1 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/proportions.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/proportions.kt @@ -117,7 +117,7 @@ val BONE_SPECS: Map = mapOf( SkeletonBone.HIPS_WIDTH to BoneSpec(default = 0.26f, min = 0.01f, max = 0.6f, curve = LINEAR_WITH_HEIGHT), SkeletonBone.UPPER_LEG to BoneSpec(default = 0.4f, min = 0.01f, max = 0.8f, curve = UPPER_LEG_LENGTH_BY_STATURE), SkeletonBone.LOWER_LEG to BoneSpec(default = 0.5f, min = 0.01f, max = 0.8f, curve = LOWER_LEG_LENGTH_BY_STATURE), - SkeletonBone.FOOT_LENGTH to BoneSpec(default = 0.125f, min = 0.01f, max = 0.35f, curve = FOOT_LENGTH_BY_STATURE), + SkeletonBone.FOOT_LENGTH to BoneSpec(default = 0.115f, min = 0.01f, max = 0.35f, curve = FOOT_LENGTH_BY_STATURE), SkeletonBone.FOOT_SHIFT to BoneSpec(default = -0.02f, min = -0.2f, max = 0.2f, curve = LINEAR_WITH_HEIGHT), SkeletonBone.SHOULDERS_DISTANCE to BoneSpec(default = 0.05f, min = 0.01f, max = 0.3f, curve = LINEAR_WITH_HEIGHT), SkeletonBone.SHOULDERS_WIDTH to BoneSpec(default = 0.35f, min = 0.01f, max = 0.8f, curve = SHOULDERS_WIDTH_BY_STATURE),