mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-20 09:01:20 -08:00
Make Foot shift able to go negative
This commit is contained in:
1 parent
95c87f66e0
commit
dfd5ceca42
2 files changed
+7
-3
No files matched your search
@@ -65,7 +65,8 @@ private val BONE_VALUE_TO_HEAD_OFFSETS: Map<SkeletonBone, BodyPartMap<Vector3>>
|
||||
)
|
||||
|
||||
// Inverts an offset table so a resolved offset vector can be turned back into a SkeletonBone value.
|
||||
// The vector is inverted too ((vec/len)/len == 1/vec) so hadamard + len recovers the scalar.
|
||||
// Each direction is divided by its squared length so a dot product with the resolved offset
|
||||
// recovers the signed scalar.
|
||||
private fun invertOffsetTable(table: Map<SkeletonBone, BodyPartMap<Vector3>>): BodyPartMap<Map<SkeletonBone, Vector3>> = BodyPartMap(
|
||||
table
|
||||
.flatMap { (cfg, bones) -> bones.map { (bone, vec) -> bone to (cfg to vec / vec.lenSq()) } }
|
||||
@@ -132,7 +133,7 @@ fun toBoneOffsets(lengths: Map<SkeletonBone, Float>): BoneOffsets {
|
||||
|
||||
fun toBoneValues(tailOffsets: BodyPartMap<Vector3>, headOffsets: BodyPartMap<Vector3>): Map<SkeletonBone, Float> {
|
||||
fun invert(offsets: BodyPartMap<Vector3>, table: BodyPartMap<Map<SkeletonBone, Vector3>>) = offsets.flatMap { (bone, vec) ->
|
||||
table[bone]?.map { (cfg, cfgVec) -> cfg to vec.hadamard(cfgVec).len() } ?: emptyList()
|
||||
table[bone]?.map { (cfg, cfgVec) -> cfg to vec.dot(cfgVec) } ?: emptyList()
|
||||
}
|
||||
|
||||
return (invert(tailOffsets, BONE_OFFSET_TO_VALUES) + invert(headOffsets, BONE_HEAD_OFFSET_TO_VALUES))
|
||||
|
||||
@@ -27,6 +27,9 @@ import solarxr_protocol.rpc.SkeletonProportionsResponse
|
||||
|
||||
private const val MIN_HEIGHT = 0.9f
|
||||
|
||||
// Bones whose value is a signed offset rather than a length, so negatives are valid.
|
||||
private val SIGNED_BONES = setOf(SkeletonBone.FOOT_SHIFT)
|
||||
|
||||
class SkeletonProportionsBehaviour(
|
||||
private val userConfig: UserConfig,
|
||||
private val skeleton: Skeleton,
|
||||
@@ -82,7 +85,7 @@ class SkeletonProportionsBehaviour(
|
||||
receiver.rpcDispatcher.on<ChangeSkeletonProportionsRequest> { req ->
|
||||
val bone = req.bone
|
||||
if (bone == SkeletonBone.NONE) return@on
|
||||
val value = req.value.coerceAtLeast(0f)
|
||||
val value = if (bone in SIGNED_BONES) req.value else req.value.coerceAtLeast(0f)
|
||||
|
||||
userConfig.context.dispatch(UserConfigActions.Update { copy(proportions = proportions + (bone.name to value)) })
|
||||
}.launchIn(receiver.context.scope)
|
||||
|
||||
Reference in new issue
Block a user