mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-25 19:41:20 -08:00
make foot plant and toe snap less agressive
This commit is contained in:
1 parent
292da8d91f
commit
7cf14188e6
2 files changed
+32
-13
No files matched your search
@@ -1,23 +1,36 @@
|
||||
package dev.slimevr.skeleton.fkprocessors
|
||||
|
||||
import com.jme3.math.FastMath
|
||||
import dev.slimevr.skeleton.ComputedSkeleton
|
||||
import dev.slimevr.skeleton.InputSkeleton
|
||||
import dev.slimevr.skeleton.Skeleton
|
||||
import dev.slimevr.skeleton.SkeletonFkProcessor
|
||||
import io.github.axisangles.ktmath.Quaternion
|
||||
import io.github.axisangles.ktmath.Vector3
|
||||
import solarxr_protocol.datatypes.BodyPart
|
||||
import kotlin.math.abs
|
||||
|
||||
// The max height to plant feet by
|
||||
const val ROTATION_CORRECTION_VERTICAL = 0.1f
|
||||
private const val ROTATION_CORRECTION_VERTICAL = 0.1f
|
||||
private const val ANKLE_DOWN_MIN = 0.35f
|
||||
private const val ANKLE_DOWN_MAX = 0.63f
|
||||
|
||||
fun computeFootPlantRatio(
|
||||
ankleHeight: Float,
|
||||
floorLevel: Float,
|
||||
ankleLocalPosition: Vector3,
|
||||
): Float {
|
||||
val ankleHeightAboveFloor = ankleHeight - floorLevel
|
||||
val ratioOfRangeFromFloor = (ankleHeightAboveFloor / ROTATION_CORRECTION_VERTICAL).coerceIn(0f, 1f)
|
||||
|
||||
// Ratio of range *to* floor
|
||||
return 1f - ratioOfRangeFromFloor
|
||||
val rangeToFloorRatio = 1f - ratioOfRangeFromFloor
|
||||
|
||||
// Lessen the ratio as the ankle doesn't point down
|
||||
val ankleDownDirection = abs(ankleLocalPosition.unit().y.coerceAtMost(0f))
|
||||
val ankleDownRatio = FastMath.remapClamped(ankleDownDirection, ANKLE_DOWN_MIN, ANKLE_DOWN_MAX, 0f, 1f)
|
||||
|
||||
return rangeToFloorRatio * ankleDownRatio
|
||||
}
|
||||
|
||||
fun correctFootAttitude(
|
||||
@@ -27,21 +40,26 @@ fun correctFootAttitude(
|
||||
): Quaternion = rotation.interpQ(rotation.eulerHeading(), correctionRatio)
|
||||
|
||||
class FootPlantFkProcessor(val skeleton: Skeleton) : SkeletonFkProcessor {
|
||||
val bodyParts: Array<BodyPart> = arrayOf(BodyPart.LEFT_FOOT, BodyPart.RIGHT_FOOT)
|
||||
|
||||
val bodyParts = arrayOf(
|
||||
BodyPart.LEFT_LOWER_LEG to BodyPart.LEFT_FOOT,
|
||||
BodyPart.RIGHT_LOWER_LEG to BodyPart.RIGHT_FOOT,
|
||||
)
|
||||
override fun process(mutableInputSkeleton: InputSkeleton, fk: ComputedSkeleton, floorLevel: Float) {
|
||||
if (!skeleton.effectiveFootPlant) return
|
||||
|
||||
for (bodyPart in bodyParts) {
|
||||
val input = mutableInputSkeleton[bodyPart] ?: continue
|
||||
for ((anklePart, footPart) in bodyParts) {
|
||||
val input = mutableInputSkeleton[footPart] ?: continue
|
||||
if (input.isRotationActive) continue
|
||||
val output = fk[bodyPart] ?: continue
|
||||
mutableInputSkeleton[bodyPart] = input.copy(
|
||||
|
||||
val foot = fk[footPart] ?: continue
|
||||
val ankle = fk[anklePart] ?: continue
|
||||
mutableInputSkeleton[footPart] = input.copy(
|
||||
rotation = correctFootAttitude(
|
||||
input.rotation,
|
||||
computeFootPlantRatio(
|
||||
output.headPosition.y,
|
||||
foot.headPosition.y,
|
||||
floorLevel,
|
||||
ankle.localTailPosition,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -10,10 +10,10 @@ import io.github.axisangles.ktmath.Vector3
|
||||
import solarxr_protocol.datatypes.BodyPart
|
||||
import kotlin.math.abs
|
||||
|
||||
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
|
||||
private const val TOE_SNAP_RANGE_MULTIPLIER = 1.64f
|
||||
private const val MAX_TOE_SNAP_RATIO = 0.8f
|
||||
private const val ANKLE_DOWN_MIN = 0.75f
|
||||
private const val ANKLE_DOWN_MAX = 0.94f
|
||||
|
||||
fun computeToeSnapRatio(
|
||||
ankleHeight: Float,
|
||||
@@ -65,6 +65,7 @@ class ToeSnapFkProcessor(val skeleton: Skeleton) : SkeletonFkProcessor {
|
||||
if (input.isRotationActive) continue
|
||||
val length = input.offset.len()
|
||||
if (length <= 0f) continue
|
||||
|
||||
val ankle = fk[anklePart] ?: continue
|
||||
val foot = fk[footPart] ?: continue
|
||||
mutableInputSkeleton[footPart] = input.copy(
|
||||
|
||||
Reference in new issue
Block a user