From f986f507aefe1a014b34a5693aed8373f753a6b2 Mon Sep 17 00:00:00 2001 From: Butterscotch! Date: Mon, 20 Jul 2026 05:54:03 -0400 Subject: [PATCH] Rename RawBone to BoneInput --- .../java/dev/slimevr/skeleton/behaviours.kt | 16 +++++++------- .../src/main/java/dev/slimevr/skeleton/ik.kt | 6 ++--- .../main/java/dev/slimevr/skeleton/module.kt | 13 +++++------ .../java/dev/slimevr/skeleton/processors.kt | 22 +++++++++---------- .../dev/slimevr/skeleton/skatingcorrection.kt | 4 ++-- .../slimevr/solarxr/skeletonproportions.kt | 2 +- 6 files changed, 31 insertions(+), 32 deletions(-) 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 58810072a..93f1aa9c9 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/behaviours.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/behaviours.kt @@ -17,24 +17,24 @@ import kotlin.math.sin class BoneTransformBehaviour : SkeletonBehaviour { override fun reduce(state: SkeletonState, action: SkeletonActions): SkeletonState = when (action) { is SkeletonActions.SetBoneRotation -> { - val bones = state.rawBones.toMutableMap() + val bones = state.boneInputs.toMutableMap() val bone = bones[action.bodyPart] ?: return state bones[action.bodyPart] = bone.copy(rawRotation = action.rotation, isActive = true) - state.copy(rawBones = bones) + state.copy(boneInputs = bones) } is SkeletonActions.SetBonePosition -> { - val bones = state.rawBones.toMutableMap() + val bones = state.boneInputs.toMutableMap() val bone = bones[action.bodyPart] ?: return state bones[action.bodyPart] = bone.copy(rawPosition = action.position, isActive = true) - state.copy(rawBones = bones) + state.copy(boneInputs = bones) } is SkeletonActions.DisableBone -> { - val bones = state.rawBones.toMutableMap() + val bones = state.boneInputs.toMutableMap() val bone = bones[action.bodyPart] ?: return state bones[action.bodyPart] = bone.copy(isActive = false) - state.copy(rawBones = bones) + state.copy(boneInputs = bones) } else -> state @@ -45,10 +45,10 @@ class ProportionsBehaviour(private val userConfig: UserConfig) : SkeletonBehavio override fun reduce(state: SkeletonState, action: SkeletonActions): SkeletonState = when (action) { is SkeletonActions.SetProportions -> { val bones = action.lengths.toBoneOffsets() - val newBones = state.rawBones.mapValues { (bodyPart, bone) -> + val newBones = state.boneInputs.mapValues { (bodyPart, bone) -> bone.copy(offset = bones[bodyPart] ?: bone.offset) } - state.copy(rawBones = newBones, skeletonHeight = action.lengths.height()) + state.copy(boneInputs = newBones, skeletonHeight = action.lengths.height()) } else -> state diff --git a/server/core/src/main/java/dev/slimevr/skeleton/ik.kt b/server/core/src/main/java/dev/slimevr/skeleton/ik.kt index 9656cd50a..5fe480504 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/ik.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/ik.kt @@ -21,12 +21,12 @@ fun chainCanReach(bones: Map, chain: List, target } // Single loop over a chain -fun ccdIk(rawBones: Map, bones: Map, chain: List, target: Vector3): Map { - val workingBones = rawBones.toMutableMap() +fun ccdIk(boneInputs: Map, bones: Map, chain: List, target: Vector3): Map { + val workingBones = boneInputs.toMutableMap() // Reversed index, i increases backwards up the chain for ((i, bodyPart) in chain.reversed().withIndex()) { - val currentRawBone = requireNotNull(rawBones[bodyPart]) + val currentRawBone = requireNotNull(boneInputs[bodyPart]) val currentBone = requireNotNull(bones[bodyPart]) val localOffset = currentBone.localTailPosition diff --git a/server/core/src/main/java/dev/slimevr/skeleton/module.kt b/server/core/src/main/java/dev/slimevr/skeleton/module.kt index 7538e40be..b7d19e9ac 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/module.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/module.kt @@ -1,6 +1,5 @@ package dev.slimevr.skeleton -import com.jme3.math.FastMath import dev.slimevr.Phase1ContextProvider import dev.slimevr.context.Behaviour import dev.slimevr.context.Context @@ -11,7 +10,7 @@ import kotlinx.coroutines.flow.MutableStateFlow import solarxr_protocol.datatypes.BodyPart import solarxr_protocol.rpc.SkeletonBone -data class RawBone( +data class BoneInput( val bodyPart: BodyPart, val offset: Vector3, val rawRotation: Quaternion, @@ -35,20 +34,20 @@ data class BoneState( get() = tailPosition - headPosition } -data class SkeletonState(val rawBones: Map, val skeletonHeight: Float, val paused: Boolean) +data class SkeletonState(val boneInputs: Map, val skeletonHeight: Float, val paused: Boolean) val DEFAULT_SKELETON_STATE: SkeletonState = run { val bones = DEFAULT_BONE_OFFSETS.entries.associate { (bodyPart, tailOffset) -> bodyPart to BoneState(bodyPart = bodyPart, offset = tailOffset) } SkeletonState( - rawBones = bones.mapValues { (_, bone) -> RawBone(rawRotation = bone.rotation, bodyPart = bone.bodyPart, offset = bone.offset, rawPosition = Vector3.NULL, isActive = false) }, + boneInputs = bones.mapValues { (_, bone) -> BoneInput(rawRotation = bone.rotation, bodyPart = bone.bodyPart, offset = bone.offset, rawPosition = Vector3.NULL, isActive = false) }, skeletonHeight = DEFAULT_HEIGHT, paused = false, ) } -fun buildBone(bone: RawBone, parentBone: BoneState?, originPosition: Vector3 = Vector3.NULL): BoneState { +fun buildBone(bone: BoneInput, parentBone: BoneState?, originPosition: Vector3 = Vector3.NULL): BoneState { val head = parentBone?.tailPosition ?: originPosition return BoneState( bodyPart = bone.bodyPart, @@ -61,7 +60,7 @@ fun buildBone(bone: RawBone, parentBone: BoneState?, originPosition: Vector3 = V } fun buildBones( - state: Map, + state: Map, rootHead: Vector3 = Vector3.NULL, hierarchy: Sequence> = iterateBodyPartHierarchy(), ): Map { @@ -78,7 +77,7 @@ fun buildBones( state: SkeletonState, rootHead: Vector3 = Vector3.NULL, hierarchy: Sequence> = iterateBodyPartHierarchy(), -): Map = buildBones(state.rawBones, rootHead, hierarchy) +): Map = buildBones(state.boneInputs, rootHead, hierarchy) sealed interface SkeletonActions { data class SetBoneRotation(val bodyPart: BodyPart, val rotation: Quaternion) : SkeletonActions diff --git a/server/core/src/main/java/dev/slimevr/skeleton/processors.kt b/server/core/src/main/java/dev/slimevr/skeleton/processors.kt index 9f197327c..7c3a51aae 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/processors.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/processors.kt @@ -101,10 +101,10 @@ class FallbackProcessor : SkeletonProcessor { ) override fun process(state: SkeletonState): SkeletonState { - val rawBones = state.rawBones + val rawBones = state.boneInputs return state.copy( - rawBones = rawBones.mapValues { (bodyPart, bone) -> + boneInputs = rawBones.mapValues { (bodyPart, bone) -> if (bone.isActive) return@mapValues bone bone.copy(rawRotation = computeFallbackRotation(rawBones, bodyPart)) @@ -112,18 +112,18 @@ class FallbackProcessor : SkeletonProcessor { ) } - private fun computeFallbackRotation(rawBones: Map, bodyPart: BodyPart): Quaternion { + private fun computeFallbackRotation(boneInputs: Map, bodyPart: BodyPart): Quaternion { // Fallback bone's rotation missingToFallbacks[bodyPart] ?.firstNotNullOfOrNull { part -> - rawBones[part]?.takeIf { it.isActive } + boneInputs[part]?.takeIf { it.isActive } } ?.let { return it.rawRotation } // First active parent bone's yaw - rawBones[ + boneInputs[ findBodyPartParent(bodyPart) { part -> - rawBones[part]?.isActive == true + boneInputs[part]?.isActive == true }, ]?.let { return it.rawRotation.project(Vector3.POS_Y).unit() } @@ -153,15 +153,15 @@ class SmoothingProcessor(val settings: Settings) : SkeletonProcessor { val alpha = 1 - (SMOOTH_MIN + config.amount.coerceIn(0f, 1f) * (SMOOTH_MAX - SMOOTH_MIN)) - smoothedRotations = state.rawBones.mapValues { (bodyPart, bone) -> + smoothedRotations = state.boneInputs.mapValues { (bodyPart, bone) -> (smoothedRotations[bodyPart] ?: bone.rawRotation).lerpR(bone.rawRotation, alpha).unit() } - smoothedLengths = state.rawBones.mapValues { (bodyPart, bone) -> + smoothedLengths = state.boneInputs.mapValues { (bodyPart, bone) -> val prev = smoothedLengths[bodyPart] ?: bone.offset prev + (bone.offset - prev) * alpha } return state.copy( - rawBones = state.rawBones.mapValues { (bodyPart, bone) -> + boneInputs = state.boneInputs.mapValues { (bodyPart, bone) -> bone.copy( rawRotation = smoothedRotations[bodyPart] ?: bone.rawRotation, offset = smoothedLengths[bodyPart] ?: bone.offset, @@ -191,7 +191,7 @@ class PredictionProcessor(val settings: Settings) : SkeletonProcessor { if (config.type != FilteringType.PREDICTION) return state val newVelocities = mutableMapOf() - val newBones = state.rawBones.mapValues { (bodyPart, bone) -> + val newBones = state.boneInputs.mapValues { (bodyPart, bone) -> val prev = velocities[bodyPart] if (prev == null) { newVelocities[bodyPart] = BoneVelocity(bone.rawRotation, Quaternion.IDENTITY, bone.offset, Vector3.NULL) @@ -215,6 +215,6 @@ class PredictionProcessor(val settings: Settings) : SkeletonProcessor { ) } velocities = newVelocities - return state.copy(rawBones = newBones) + return state.copy(boneInputs = newBones) } } diff --git a/server/core/src/main/java/dev/slimevr/skeleton/skatingcorrection.kt b/server/core/src/main/java/dev/slimevr/skeleton/skatingcorrection.kt index b3503961b..7784668b7 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/skatingcorrection.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/skatingcorrection.kt @@ -161,8 +161,8 @@ class FloorClipProcessor : SkeletonProcessor { fun getDisplacement(footPos: Vector3): Vector3 = Vector3(0f, footPos.y.coerceAtMost(0f), 0f) override fun process(state: SkeletonState): SkeletonState { - val newBones = state.rawBones.mapValues { (bodyPart, bone) -> } - state.rawBones[BodyPart.LEFT_FOOT]?.let { + val newBones = state.boneInputs.mapValues { (bodyPart, bone) -> } + state.boneInputs[BodyPart.LEFT_FOOT]?.let { val correction = getDisplacement(it.offset) // TODO Apply displacement onto skeleton } diff --git a/server/core/src/main/java/dev/slimevr/solarxr/skeletonproportions.kt b/server/core/src/main/java/dev/slimevr/solarxr/skeletonproportions.kt index a3a7843cb..9a8e52ef5 100644 --- a/server/core/src/main/java/dev/slimevr/solarxr/skeletonproportions.kt +++ b/server/core/src/main/java/dev/slimevr/solarxr/skeletonproportions.kt @@ -24,7 +24,7 @@ class SkeletonProportionsBehaviour( private fun buildConfigResponse(): SkeletonProportionsResponse { val proportions = userConfig.context.state.value.data.proportions - val bones = skeleton.context.state.value.rawBones + val bones = skeleton.context.state.value.boneInputs val skeletonParts = bones.mapValues { it.value.offset }.toBoneValues().map { (offset, bone) -> SkeletonPart(offset, bone) } val expanded = configToBoneValues(proportions) val userHeight = if (expanded.isNotEmpty()) {