diff --git a/server/core/src/main/java/dev/slimevr/skeleton/bodypart-structure.kt b/server/core/src/main/java/dev/slimevr/skeleton/bodypart-structure.kt index 4657c9f3d..c6191d243 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/bodypart-structure.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/bodypart-structure.kt @@ -115,7 +115,7 @@ fun highestBodyParts(bodyParts: Set): Set { return result } -private fun buildHierarchy(root: BodyPart, onlyChildren: Boolean): Array> { +private fun buildHierarchy(root: BodyPart, onlyChildren: Boolean): List> { val result = mutableListOf>() 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>> = +private val BODY_PART_HIERARCHIES: Array>> = 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> = BODY_PART_HIERARCHIES[root.ordinal * 2 + if (onlyChildren) 1 else 0] +): List> = BODY_PART_HIERARCHIES[root.ordinal * 2 + if (onlyChildren) 1 else 0] 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 2517fcfa5..8cf9b93d8 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/proportions.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/proportions.kt @@ -119,7 +119,7 @@ val BONE_SPECS: Map = 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), diff --git a/server/core/src/main/java/dev/slimevr/vmc/input-decoder.kt b/server/core/src/main/java/dev/slimevr/vmc/input-decoder.kt index a113b8f2b..e5b33370c 100644 --- a/server/core/src/main/java/dev/slimevr/vmc/input-decoder.kt +++ b/server/core/src/main/java/dev/slimevr/vmc/input-decoder.kt @@ -83,7 +83,7 @@ internal fun parseVmcTransform(args: List, startIndex: Int): Pair() + val locals = EnumMap(mapOf(UnityBone.HIPS to hipLocalRotation)) + val localPositions: EnumMap = EnumMap(UnityBone::class.java) val result = vmcWorldTransforms(locals, localPositions, rootRotation, rootPosition, scale = 1f) - val hip = assertNotNull(result[BodyPart.HIP]) + val hip = assertNotNull(result[UnityBone.HIPS]) assertApprox(rootRotation * hipLocalRotation, hip.rotation) assertApprox(rootPosition, hip.position) @@ -176,16 +176,16 @@ class InputDecoderTest { @Test fun `Scale multiplies position and leaves rotation alone`() { - val locals = BodyPartMap(mapOf(BodyPart.HIP to Quaternion.rotationAroundZAxis(0.3f))) - val localPositions = BodyPartMap(mapOf(BodyPart.HIP to Vector3(1f, 2f, 3f))) + val locals = EnumMap(mapOf(UnityBone.HIPS to Quaternion.rotationAroundZAxis(0.3f))) + val localPositions = EnumMap(mapOf(UnityBone.HIPS to Vector3(1f, 2f, 3f))) val unscaled = vmcWorldTransforms(locals, localPositions, Quaternion.IDENTITY, Vector3.ZERO, scale = 1f) val scaled = vmcWorldTransforms(locals, localPositions, Quaternion.IDENTITY, Vector3.ZERO, scale = 2f) - assertApprox(Quaternion.rotationAroundZAxis(0.3f), assertNotNull(scaled[BodyPart.HIP]).rotation) + assertApprox(Quaternion.rotationAroundZAxis(0.3f), assertNotNull(scaled[UnityBone.HIPS]).rotation) assertApprox( - assertNotNull(unscaled[BodyPart.HIP]).position * 2f, - assertNotNull(scaled[BodyPart.HIP]).position, + assertNotNull(unscaled[UnityBone.HIPS]).position * 2f, + assertNotNull(scaled[UnityBone.HIPS]).position, ) } @@ -196,17 +196,17 @@ class InputDecoderTest { // A sender whose model has no UpperChest bone never emits its local rotation, so it's // absent from the decoded locals map entirely. This should behave exactly as if // UpperChest's local rotation had been received as IDENTITY. - val withoutUpperChest = BodyPartMap(mapOf(BodyPart.NECK to neckLocal)) - val withIdentityUpperChest = BodyPartMap( - mapOf(BodyPart.NECK to neckLocal, BodyPart.UPPER_CHEST to Quaternion.IDENTITY), + val withoutUpperChest = EnumMap(mapOf(UnityBone.NECK to neckLocal)) + val withIdentityUpperChest = EnumMap( + mapOf(UnityBone.NECK to neckLocal, UnityBone.UPPER_CHEST to Quaternion.IDENTITY), ) - val emptyPositions = bodyPartMap() + val emptyPositions: EnumMap = EnumMap(UnityBone::class.java) val a = vmcWorldTransforms(withoutUpperChest, emptyPositions, Quaternion.IDENTITY, Vector3.ZERO, 1f) val b = vmcWorldTransforms(withIdentityUpperChest, emptyPositions, Quaternion.IDENTITY, Vector3.ZERO, 1f) - assertApprox(assertNotNull(a[BodyPart.NECK]).rotation, assertNotNull(b[BodyPart.NECK]).rotation) - assertApprox(assertNotNull(a[BodyPart.HEAD]).rotation, assertNotNull(b[BodyPart.HEAD]).rotation) + assertApprox(assertNotNull(a[UnityBone.NECK]).rotation, assertNotNull(b[UnityBone.NECK]).rotation) + assertApprox(assertNotNull(a[UnityBone.HEAD]).rotation, assertNotNull(b[UnityBone.HEAD]).rotation) } @Test diff --git a/server/core/src/test/java/dev/slimevr/vmc/OutputEncoderTest.kt b/server/core/src/test/java/dev/slimevr/vmc/OutputEncoderTest.kt index 4c18ff3b8..baa806bea 100644 --- a/server/core/src/test/java/dev/slimevr/vmc/OutputEncoderTest.kt +++ b/server/core/src/test/java/dev/slimevr/vmc/OutputEncoderTest.kt @@ -93,7 +93,7 @@ class OutputEncoderTest { fun testSkipsRoutedBonesMissingFromTheSkeleton() { val bundle = buildOutgoingBundle( bones = BodyPartMap(mapOf(BodyPart.HIP to bone(BodyPart.HIP))), - routedBones = setOf(BodyPart.HIP, BodyPart.LOWER_WAIST), + routedBones = setOf(BodyPart.HIP, BodyPart.LOWER_WAIST, BodyPart.UPPER_WAIST), config = defaultConfig, vrm = null, skeletonHeight = 1.7f, diff --git a/server/core/src/test/java/dev/slimevr/vmc/VMCInputBehaviourTest.kt b/server/core/src/test/java/dev/slimevr/vmc/VMCInputBehaviourTest.kt index 699fc6344..de0e1db89 100644 --- a/server/core/src/test/java/dev/slimevr/vmc/VMCInputBehaviourTest.kt +++ b/server/core/src/test/java/dev/slimevr/vmc/VMCInputBehaviourTest.kt @@ -22,6 +22,7 @@ import kotlinx.coroutines.test.runTest import solarxr_protocol.datatypes.BodyPart import solarxr_protocol.datatypes.DeviceOrigin import solarxr_protocol.rpc.VMCOSCVrmState +import java.util.EnumMap import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotNull @@ -117,7 +118,7 @@ class VMCInputBehaviourTest { harness.receiver.context.dispatch( VMCActions.SetVrm( state = VMCOSCVrmState.LOADED, - vrm = VrmGeometry(bindOffsets = bodyPartMap(), hipPosition = Vector3.ZERO, vrmHeight = skeletonHeight / 2f, outputRestHeight = skeletonHeight / 2f), + vrm = VrmGeometry(bindOffsets = EnumMap(UnityBone::class.java), hipPosition = Vector3.ZERO, vrmHeight = skeletonHeight / 2f, outputRestHeight = skeletonHeight / 2f, hasUpperChest = true), ), )