mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-12-06 08:42:32 -08:00
Fix tests
This commit is contained in:
1 parent
a66c43feb7
commit
a366e4c20c
8 files changed
+34
-30
No files matched your search
@@ -115,7 +115,7 @@ fun highestBodyParts(bodyParts: Set<BodyPart>): Set<BodyPart> {
|
||||
return result
|
||||
}
|
||||
|
||||
private fun buildHierarchy(root: BodyPart, onlyChildren: Boolean): Array<Pair<BodyPart?, BodyPart>> {
|
||||
private fun buildHierarchy(root: BodyPart, onlyChildren: Boolean): List<Pair<BodyPart?, BodyPart>> {
|
||||
val result = mutableListOf<Pair<BodyPart?, BodyPart>>()
|
||||
fun visit(parentBone: BodyPart?, bone: BodyPart, skipSelf: Boolean) {
|
||||
if (!skipSelf) result += parentBone to bone
|
||||
@@ -123,16 +123,16 @@ private fun buildHierarchy(root: BodyPart, onlyChildren: Boolean): Array<Pair<Bo
|
||||
for (child in children) visit(bone, child, false)
|
||||
}
|
||||
visit(null, root, onlyChildren)
|
||||
return result.toTypedArray()
|
||||
return result
|
||||
}
|
||||
|
||||
// The hierarchy is constant, so every traversal of it is too. Derived once for the same reason
|
||||
// BODY_PART_PARENTS is: walking it lazily per call cost a continuation and a Pair per bone, and
|
||||
// BoneYawFallbackProcessor asks for one per active bone per frame.
|
||||
private val BODY_PART_HIERARCHIES: Array<Array<Pair<BodyPart?, BodyPart>>> =
|
||||
private val BODY_PART_HIERARCHIES: Array<List<Pair<BodyPart?, BodyPart>>> =
|
||||
Array(ALL_BODY_PARTS.size * 2) { index -> buildHierarchy(ALL_BODY_PARTS[index / 2], index % 2 == 1) }
|
||||
|
||||
fun iterateBodyPartHierarchy(
|
||||
root: BodyPart = BodyPart.HEAD,
|
||||
onlyChildren: Boolean = false,
|
||||
): Array<Pair<BodyPart?, BodyPart>> = BODY_PART_HIERARCHIES[root.ordinal * 2 + if (onlyChildren) 1 else 0]
|
||||
): List<Pair<BodyPart?, BodyPart>> = BODY_PART_HIERARCHIES[root.ordinal * 2 + if (onlyChildren) 1 else 0]
|
||||
@@ -119,7 +119,7 @@ val BONE_SPECS: Map<SkeletonBone, BoneSpec> = mapOf(
|
||||
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_SHIFT to BoneSpec(default = -0.02f, min = -0.2f, max = 0.2f, curve = LINEAR_WITH_HEIGHT),
|
||||
SkeletonBone.SHOULDERS_DISTANCE to BoneSpec(default = 0.06f, min = 0.01f, max = 0.3f, 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),
|
||||
SkeletonBone.UPPER_ARM to BoneSpec(default = 0.29f, min = 0.01f, max = 0.6f, curve = UPPER_ARM_LENGTH_BY_STATURE),
|
||||
SkeletonBone.LOWER_ARM to BoneSpec(default = 0.27f, min = 0.01f, max = 0.6f, curve = LOWER_ARM_LENGTH_BY_STATURE),
|
||||
|
||||
@@ -83,7 +83,7 @@ internal fun parseVmcTransform(args: List<OscArg>, startIndex: Int): Pair<Vector
|
||||
data class VmcBoneTransform(val rotation: Quaternion, val position: Vector3)
|
||||
|
||||
/**
|
||||
* Inverse of vmcLocalRotation/vmcLocalPosition (output-encoder.kt): walks VMC_INPUT_BONE_ORDER
|
||||
* Inverse of vmcLocalRotation/vmcLocalPosition (output-encoder.kt): walks VMC_BONE_ORDER
|
||||
* parent-before-child, accumulating VMC's parent-local bone rotations/positions into world
|
||||
* rotations and positions.
|
||||
*/
|
||||
|
||||
@@ -47,8 +47,10 @@ internal fun buildOutgoingBundle(
|
||||
} else {
|
||||
unityBone.bodyParts
|
||||
}
|
||||
unityBoneGlobalRotations[unityBone] = averageRotations(bodyParts.mapNotNull { bones[it]?.rotation })
|
||||
unityBoneGlobalPositions[unityBone] = averagePositions(bodyParts.mapNotNull { bones[it]?.headPosition })
|
||||
val bones = bodyParts.mapNotNull { bones[it] }
|
||||
if (bones.isEmpty()) continue
|
||||
unityBoneGlobalRotations[unityBone] = averageRotations(bones.map { it.rotation })
|
||||
unityBoneGlobalPositions[unityBone] = averagePositions(bones.map { it.headPosition })
|
||||
}
|
||||
|
||||
// Send data for each bone
|
||||
@@ -60,8 +62,8 @@ internal fun buildOutgoingBundle(
|
||||
val trackingParentUnityBone = VMC_BONE_PARENTS[trackingUnityBone]
|
||||
|
||||
// Compute local rotation of bone
|
||||
val boneRotation = unityBoneGlobalRotations[trackingUnityBone] ?: Quaternion.IDENTITY
|
||||
val parentRotation = unityBoneGlobalRotations[trackingParentUnityBone] ?: Quaternion.IDENTITY
|
||||
val boneRotation = unityBoneGlobalRotations[trackingUnityBone] ?: continue
|
||||
val parentRotation = unityBoneGlobalRotations[trackingParentUnityBone]
|
||||
val localRotation = vmcLocalRotation(boneRotation, parentRotation, targetUnityBone, targetParentUnityBone, config.mirrorTracking)
|
||||
|
||||
// Compute local position of bone
|
||||
@@ -79,7 +81,7 @@ internal fun buildOutgoingBundle(
|
||||
} else {
|
||||
val bonePosition = unityBoneGlobalPositions[trackingUnityBone] ?: Vector3.ZERO
|
||||
val parentPosition = unityBoneGlobalPositions[trackingParentUnityBone] ?: Vector3.ZERO
|
||||
emittedLocalPosition(targetUnityBone, targetParentUnityBone, bonePosition, parentRotation, parentPosition, vrm, config.mirrorTracking)
|
||||
emittedLocalPosition(targetUnityBone, targetParentUnityBone, bonePosition, parentRotation ?: Quaternion.IDENTITY, parentPosition, vrm, config.mirrorTracking)
|
||||
}
|
||||
|
||||
add(
|
||||
|
||||
@@ -169,5 +169,6 @@ enum class UnityBone(
|
||||
|
||||
companion object {
|
||||
fun fromSerial(serial: String): UnityBone? = entries.firstOrNull { it.serial.equals(serial, ignoreCase = true) }
|
||||
fun fromBodyPart(bodyPart: BodyPart): UnityBone? = entries.firstOrNull { bodyPart in it.bodyParts }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user