diff --git a/server/core/src/main/java/dev/slimevr/skeleton/behaviours.kt b/server/core/src/main/java/dev/slimevr/skeleton/behaviours.kt index 4a3801398..a5f3bb8b6 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/behaviours.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/behaviours.kt @@ -122,22 +122,22 @@ class ComputedSkeletonBehaviour( val fk = buildBones(processedInputs, rootHead) // Run IK processors - val ikTargets = targetProcessors.fold(bodyPartMap()) { targets, processor -> processor.process(fk, targets) } + val ikTargets = targetProcessors.fold(bodyPartMap()) { targets, processor -> processor.process(fk, targets) } // Run IK - val ikOutput = ccdIk( - processedInputs, - fk, - ikTargets.map { (bodyPart, target) -> - IKChainGoal( - listOf(bodyPart), - target, - ) - }, - null, - 0.01f, - 100, - ) + val ikOutput = ccdIk( + processedInputs, + fk, + ikTargets.map { (bodyPart, target) -> + IKChainGoal( + listOf(bodyPart), + target, + ) + }, + null, + 0.01f, + 100, + ) // Updated the computed skeleton with the result receiver.computed.tryEmit(ikOutput.bones) diff --git a/server/core/src/main/java/dev/slimevr/skeleton/processors/bone-active-link.kt b/server/core/src/main/java/dev/slimevr/skeleton/processors/bone-active-link.kt index 1188cc715..ddbf2acfa 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/processors/bone-active-link.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/processors/bone-active-link.kt @@ -23,17 +23,15 @@ class BoneActiveLinkProcessor : SkeletonProcessor { BodyPart.HIP to arrayOf(BodyPart.WAIST, BodyPart.CHEST, BodyPart.UPPER_CHEST), ) - override fun process(inputSkeleton: InputSkeleton): InputSkeleton { - return inputSkeleton.mutate { updated -> - for ((bodyPart, sources) in linkedToSources) { - val bone = inputSkeleton.getValue(bodyPart) - if (bone.isActive) continue + override fun process(inputSkeleton: InputSkeleton): InputSkeleton = inputSkeleton.mutate { updated -> + for ((bodyPart, sources) in linkedToSources) { + val bone = inputSkeleton.getValue(bodyPart) + if (bone.isActive) continue - val closestActiveBone = sources.firstNotNullOfOrNull { part -> - inputSkeleton[part]?.takeIf { it.isActive } - } ?: continue - updated[bodyPart] = bone.copy(rawRotation = closestActiveBone.rawRotation) - } + val closestActiveBone = sources.firstNotNullOfOrNull { part -> + inputSkeleton[part]?.takeIf { it.isActive } + } ?: continue + updated[bodyPart] = bone.copy(rawRotation = closestActiveBone.rawRotation) } } } diff --git a/server/core/src/main/java/dev/slimevr/skeleton/processors/bone-direct-link.kt b/server/core/src/main/java/dev/slimevr/skeleton/processors/bone-direct-link.kt index 9a1bad445..05febbac8 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/processors/bone-direct-link.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/processors/bone-direct-link.kt @@ -37,15 +37,13 @@ class BoneDirectLinkProcessor : SkeletonProcessor { BodyPart.RIGHT_HAND to BodyPart.RIGHT_LOWER_ARM, ) - override fun process(inputSkeleton: InputSkeleton): InputSkeleton { - return inputSkeleton.mutate { updated -> - for ((bodyPart, source) in linkedToSource) { - val bone = updated.getValue(bodyPart) - if (bone.isActive) continue + override fun process(inputSkeleton: InputSkeleton): InputSkeleton = inputSkeleton.mutate { updated -> + for ((bodyPart, source) in linkedToSource) { + val bone = updated.getValue(bodyPart) + if (bone.isActive) continue - val sourceBone = updated[source] - updated[bodyPart] = bone.copy(rawRotation = sourceBone?.rawRotation ?: bone.rawRotation) - } + val sourceBone = updated[source] + updated[bodyPart] = bone.copy(rawRotation = sourceBone?.rawRotation ?: bone.rawRotation) } } } diff --git a/server/core/src/main/java/dev/slimevr/skeleton/processors/finger-impute.kt b/server/core/src/main/java/dev/slimevr/skeleton/processors/finger-impute.kt index 74a8280f1..798936099 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/processors/finger-impute.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/processors/finger-impute.kt @@ -48,15 +48,13 @@ class FingerImputeProcessor : SkeletonProcessor { ) // TODO : There's more math to do here. Reference the original code. - override fun process(inputSkeleton: InputSkeleton): InputSkeleton { - return inputSkeleton.mutate { updated -> - for ((bodyPart, source) in fingerToSource) { - val bone = updated.getValue(bodyPart) - if (bone.isActive) continue + override fun process(inputSkeleton: InputSkeleton): InputSkeleton = inputSkeleton.mutate { updated -> + for ((bodyPart, source) in fingerToSource) { + val bone = updated.getValue(bodyPart) + if (bone.isActive) continue - val sourceBone = updated[source] - updated[bodyPart] = bone.copy(rawRotation = sourceBone?.rawRotation ?: bone.rawRotation) - } + val sourceBone = updated[source] + updated[bodyPart] = bone.copy(rawRotation = sourceBone?.rawRotation ?: bone.rawRotation) } } } diff --git a/server/core/src/main/java/dev/slimevr/skeleton/processors/hip-yaw-roll-align.kt b/server/core/src/main/java/dev/slimevr/skeleton/processors/hip-yaw-roll-align.kt index 7f43bf0cf..330823988 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/processors/hip-yaw-roll-align.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/processors/hip-yaw-roll-align.kt @@ -15,15 +15,13 @@ class HipYawRollAlignProcessor(val settings: Settings) : SkeletonProcessor { val source = arrayOf(BodyPart.LEFT_UPPER_LEG, BodyPart.RIGHT_UPPER_LEG) - override fun process(inputSkeleton: InputSkeleton): InputSkeleton { - return inputSkeleton.mutate { updated -> - val hipBone = updated.getValue(BodyPart.HIP) - if (!hipBone.isActive) { - val ratio = settings.context.state.value.data.skeletonConfig.ratios.interpolateHipWithUpperLegs - val sourceRotation = updated.resolveAverageRotationFor(source) - val alignedRotation = alignYawRoll(hipBone.rawRotation, sourceRotation) - updated[BodyPart.HIP] = hipBone.copy(rawRotation = hipBone.rawRotation.interpQ(alignedRotation, ratio)) - } + override fun process(inputSkeleton: InputSkeleton): InputSkeleton = inputSkeleton.mutate { updated -> + val hipBone = updated.getValue(BodyPart.HIP) + if (!hipBone.isActive) { + val ratio = settings.context.state.value.data.skeletonConfig.ratios.interpolateHipWithUpperLegs + val sourceRotation = updated.resolveAverageRotationFor(source) + val alignedRotation = alignYawRoll(hipBone.rawRotation, sourceRotation) + updated[BodyPart.HIP] = hipBone.copy(rawRotation = hipBone.rawRotation.interpQ(alignedRotation, ratio)) } }