From 12e06d4b3cea7e6605b28d80a4f9bc8d180e36bb Mon Sep 17 00:00:00 2001 From: Erimel Date: Mon, 5 Oct 2026 20:31:43 -0400 Subject: [PATCH] Floorclip more generic and work with all children --- .../skeleton/targetprocessors/floor-clip.kt | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/server/core/src/main/java/dev/slimevr/skeleton/targetprocessors/floor-clip.kt b/server/core/src/main/java/dev/slimevr/skeleton/targetprocessors/floor-clip.kt index bc5fc9302..0d19a583f 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/targetprocessors/floor-clip.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/targetprocessors/floor-clip.kt @@ -5,30 +5,37 @@ import dev.slimevr.skeleton.IKTargets import dev.slimevr.skeleton.InputSkeleton import dev.slimevr.skeleton.Skeleton import dev.slimevr.skeleton.SkeletonTargetProcessor +import dev.slimevr.skeleton.iterateBodyPartHierarchy import io.github.axisangles.ktmath.Vector3 import solarxr_protocol.datatypes.BodyPart class FloorClipTargetProcessor( val skeleton: Skeleton, + val targetParts: Array = arrayOf( + BodyPart.LEFT_LOWER_LEG, + BodyPart.RIGHT_LOWER_LEG, + ), ) : SkeletonTargetProcessor { - val ankleFootParts: Array> = arrayOf( - BodyPart.LEFT_LOWER_LEG to BodyPart.LEFT_FOOT, - BodyPart.RIGHT_LOWER_LEG to BodyPart.RIGHT_FOOT, - ) - - // TODO don't just correct feet, also correct some of the hip (20% in old code). Probably to be done on IK directly. + // TODO don't just correct ankles, also correct some of the hip (20% in old code). Probably to be done on IK directly. override fun process(mutableIkTargets: IKTargets, inputSkeleton: InputSkeleton, fk: ComputedSkeleton, floorLevel: Float) { if (!skeleton.effectiveFloorClip) return - for ((anklePart, footPart) in ankleFootParts) { - // Get existing target or make a new one at the current bone position - val ankleTarget = mutableIkTargets[anklePart] ?: fk[anklePart]?.tailPosition ?: continue - val footTarget = mutableIkTargets[footPart] ?: fk[footPart]?.tailPosition ?: continue + for (parentPart in targetParts) { + // Get existing target or make a new one at the current bone position. + val parentTargetY = mutableIkTargets[parentPart] ?: fk[parentPart]?.tailPosition ?: continue - // Snap the ankle up but foot touch floor - val ankleToFoot = (ankleTarget.y - footTarget.y).coerceAtLeast(0f) - val targetY = ankleTarget.y.coerceAtLeast(floorLevel) + ankleToFoot - mutableIkTargets[anklePart] = Vector3(ankleTarget.x, targetY, ankleTarget.z) + // Offset the parent target by the lowest child as well so that none of its active children are under the floor either. + var lowestChildTargetY = parentTargetY.y + for ((_, childPart) in iterateBodyPartHierarchy(parentPart, true)) { + if (inputSkeleton[childPart]?.isRotationActive == false) continue + val target = mutableIkTargets[childPart] ?: fk[childPart]?.tailPosition ?: continue + if (target.y < lowestChildTargetY) lowestChildTargetY = target.y + } + val childOffset = (parentTargetY.y - lowestChildTargetY).coerceAtLeast(0f) + + // Snap the parent up. + val targetY = parentTargetY.y.coerceAtLeast(floorLevel) + childOffset + mutableIkTargets[parentPart] = Vector3(parentTargetY.x, targetY, parentTargetY.z) } } }