diff --git a/server/core/src/main/java/com/jme3/math/FastMath.kt b/server/core/src/main/java/com/jme3/math/FastMath.kt index aee32ad97..085c22f45 100644 --- a/server/core/src/main/java/com/jme3/math/FastMath.kt +++ b/server/core/src/main/java/com/jme3/math/FastMath.kt @@ -663,4 +663,9 @@ object FastMath { or ((f shr 13) and 0x03ff) ).toShort() } + + /** + * Linearly interpolates between 2 numbers + */ + fun lerp(from: Float, to: Float, t: Float): Float = from + (to - from) * t } diff --git a/server/core/src/main/java/dev/slimevr/config/settings.kt b/server/core/src/main/java/dev/slimevr/config/settings.kt index 86e04ec5c..1e9924491 100644 --- a/server/core/src/main/java/dev/slimevr/config/settings.kt +++ b/server/core/src/main/java/dev/slimevr/config/settings.kt @@ -2,6 +2,7 @@ package dev.slimevr.config import dev.slimevr.context.Behaviour import dev.slimevr.context.Context +import dev.slimevr.skeleton.inputprocessors.DEFAULT_SPINE_RATIO import io.github.axisangles.ktmath.Quaternion import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job @@ -139,8 +140,8 @@ data class SkeletonTogglesConfig( // Used in SkeletonConfig @Serializable data class SkeletonRatiosConfig( - val imputeSpineFromUpperToLower: Float = 0.5f, - val imputeSpineCurvature: Float = 0.5f, + val imputeSpineFromUpperToLower: Float = DEFAULT_SPINE_RATIO, + val imputeSpineCurvature: Float = DEFAULT_SPINE_RATIO, val interpolateHipWithUpperLegs: Float = 0.25f, val interpolateUpperLegsTwistWithLowerLegs: Float = 0.85f, val skatingCorrectionStrength: Float = 0.3f, 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 c88ea5201..a19aafe34 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/behaviours.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/behaviours.kt @@ -6,9 +6,9 @@ import dev.slimevr.util.timeSource import io.github.axisangles.ktmath.Quaternion import io.github.axisangles.ktmath.Vector3 import io.ktor.utils.io.CancellationException -import kotlinx.coroutines.delay import kotlinx.coroutines.Job import kotlinx.coroutines.asCoroutineDispatcher +import kotlinx.coroutines.delay import kotlinx.coroutines.ensureActive import kotlinx.coroutines.flow.distinctUntilChangedBy import kotlinx.coroutines.flow.launchIn @@ -22,9 +22,9 @@ import java.util.concurrent.locks.LockSupport import kotlin.math.cos import kotlin.math.sin import kotlin.time.Duration -import kotlin.time.TimeSource import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds +import kotlin.time.TimeSource import kotlin.time.measureTime class ProportionsBehaviour(private val userConfig: UserConfig) : SkeletonBehaviour { @@ -101,18 +101,6 @@ class YouSpinMeRightRoundBehaviour(val inputHz: Float = 1f) : SkeletonBehaviour } } -/** - * Runs [processors] over a copy of [boneInputs]. - * - * The processors share one buffer and write into it, so the copy here is what keeps the caller's - * map, and the state it came from, untouched. - */ -private fun runInputProcessors(processors: List, boneInputs: InputSkeleton, skeletonHeight: Float): InputSkeleton { - val bones = EnumMap(boneInputs) - for (processor in processors) processor.process(bones, skeletonHeight) - return bones -} - private class TickTimings(private val hz: Int, private val window: Duration, private val target: Duration) { private val capacity = (hz * window.inWholeSeconds + hz).toInt() private val computeNanos = LongArray(capacity) @@ -198,6 +186,18 @@ class ComputedSkeletonBehaviour( return next } + /** + * Runs [processors] over a copy of [boneInputs]. + * + * The processors share one buffer and write into it, so the copy here is what keeps the caller's + * map, and the state it came from, untouched. + */ + private fun runInputProcessors(processors: List, boneInputs: InputSkeleton, skeletonHeight: Float): InputSkeleton { + val bones = EnumMap(boneInputs) + for (processor in processors) processor.process(bones, skeletonHeight) + return bones + } + override fun observe(receiver: Skeleton) { // The loop parks its thread to hit its interval, so it gets one to itself. Sharing would // starve everything else on the dispatcher, since parking blocks the thread rather than @@ -220,8 +220,8 @@ class ComputedSkeletonBehaviour( val processTime = measureTime { val targetState = receiver.context.state.value - // TODO find out a cleaner way to pause tracking that doesn't add 1 frame latency (not a priority) val boneInputs = if (targetState.pausedProcessedBoneInputs != null) { + // TODO improve pause tracking code // Use already-processed paused tracking data except for the head val headBone = targetState.boneInputs[BodyPart.HEAD] targetState.pausedProcessedBoneInputs.mutateCopy { it[BodyPart.HEAD] = headBone?.copy(position = if (headBone.isPositionActive) headBone.position else it[BodyPart.HEAD]?.position) } @@ -240,9 +240,9 @@ class ComputedSkeletonBehaviour( // Run initial FK var fk = buildBones(boneInputs) - // Run FK processors. They write into boneInputs, and this snapshot is what says - // which bones each one moved, so a processor only has to write - val beforeFk = EnumMap(boneInputs) + // Run FK processors. They write into boneInputs, and beforeFk allows figuring out + // which bones changed. + val beforeFk = BodyPartMap(boneInputs) for (processor in fkProcessors) { processor.process(boneInputs, fk, targetState.floorLevel) @@ -265,7 +265,8 @@ class ComputedSkeletonBehaviour( } // Run IK processors - val ikTargets = targetProcessors.fold(bodyPartMap()) { targets, processor -> processor.process(fk, targets, targetState.floorLevel) } + val ikTargets = bodyPartMap() + for (processor in targetProcessors) processor.process(ikTargets, fk, targetState.floorLevel) // Run IK val ikOutput = ccdIk( diff --git a/server/core/src/main/java/dev/slimevr/skeleton/fkprocessors/foot-plant.kt b/server/core/src/main/java/dev/slimevr/skeleton/fkprocessors/foot-plant.kt index 2066a5ca8..0955a1ebf 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/fkprocessors/foot-plant.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/fkprocessors/foot-plant.kt @@ -30,13 +30,13 @@ fun correctFootAttitude( class FootPlantFkProcessor(val settings: Settings) : SkeletonFkProcessor { val bodyParts: Array = arrayOf(BodyPart.LEFT_FOOT, BodyPart.RIGHT_FOOT) - override fun process(inputSkeleton: InputSkeleton, fk: ComputedSkeleton, floorLevel: Float) { + override fun process(mutableInputSkeleton: InputSkeleton, fk: ComputedSkeleton, floorLevel: Float) { if (!settings.context.state.value.data.skeletonConfig.toggles.footPlant) return for (bodyPart in bodyParts) { - val input = inputSkeleton[bodyPart] ?: continue + val input = mutableInputSkeleton[bodyPart] ?: continue val output = fk[bodyPart] ?: continue - inputSkeleton[bodyPart] = input.copy( + mutableInputSkeleton[bodyPart] = input.copy( rotation = correctFootAttitude( input.rotation, computeFootPlantRatio( diff --git a/server/core/src/main/java/dev/slimevr/skeleton/fkprocessors/localizer.kt b/server/core/src/main/java/dev/slimevr/skeleton/fkprocessors/localizer.kt index c2deced92..54c459ad8 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/fkprocessors/localizer.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/fkprocessors/localizer.kt @@ -99,8 +99,8 @@ private fun isUserSitting(fk: ComputedSkeleton): Boolean { } class LocalizerFkProcessor(val settings: Settings) : SkeletonFkProcessor { - override fun process(inputSkeleton: InputSkeleton, fk: ComputedSkeleton, floorLevel: Float) { - val headInput = inputSkeleton[BodyPart.HEAD] ?: return + override fun process(mutableInputSkeleton: InputSkeleton, fk: ComputedSkeleton, floorLevel: Float) { + val headInput = mutableInputSkeleton[BodyPart.HEAD] ?: return if (headInput.isPositionActive || !settings.context.state.value.data.skeletonConfig.toggles.mocapMode) { return } @@ -116,6 +116,6 @@ class LocalizerFkProcessor(val settings: Settings) : SkeletonFkProcessor { } val newHeadPosition = (headInput.position ?: Vector3.NULL) - travel - inputSkeleton[BodyPart.HEAD] = headInput.copy(position = newHeadPosition) + mutableInputSkeleton[BodyPart.HEAD] = headInput.copy(position = newHeadPosition) } } diff --git a/server/core/src/main/java/dev/slimevr/skeleton/fkprocessors/toe-snap.kt b/server/core/src/main/java/dev/slimevr/skeleton/fkprocessors/toe-snap.kt index b3e4a3fe6..80f9f10ab 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/fkprocessors/toe-snap.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/fkprocessors/toe-snap.kt @@ -49,14 +49,14 @@ fun snapToes( class ToeSnapFkProcessor(val settings: Settings) : SkeletonFkProcessor { val bodyParts: Array = arrayOf(BodyPart.LEFT_FOOT, BodyPart.RIGHT_FOOT) - override fun process(inputSkeleton: InputSkeleton, fk: ComputedSkeleton, floorLevel: Float) { + override fun process(mutableInputSkeleton: InputSkeleton, fk: ComputedSkeleton, floorLevel: Float) { if (!settings.context.state.value.data.skeletonConfig.toggles.toeSnap) return // TODO This loop format should be turned into a function for (bodyPart in bodyParts) { - val input = inputSkeleton[bodyPart] ?: continue + val input = mutableInputSkeleton[bodyPart] ?: continue val output = fk[bodyPart] ?: continue - inputSkeleton[bodyPart] = input.copy( + mutableInputSkeleton[bodyPart] = input.copy( rotation = snapToes( input.rotation, computeToeSnapRatio( diff --git a/server/core/src/main/java/dev/slimevr/skeleton/fkprocessors/velocity.kt b/server/core/src/main/java/dev/slimevr/skeleton/fkprocessors/velocity.kt index cc395bc21..177f73d96 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/fkprocessors/velocity.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/fkprocessors/velocity.kt @@ -1,40 +1,54 @@ package dev.slimevr.skeleton.fkprocessors +import dev.slimevr.skeleton.BodyPartMap import dev.slimevr.skeleton.BoneState import dev.slimevr.skeleton.ComputedSkeleton import dev.slimevr.skeleton.InputSkeleton import dev.slimevr.skeleton.SkeletonFkProcessor import dev.slimevr.skeleton.Velocity +import dev.slimevr.skeleton.bodyPartMap import dev.slimevr.skeleton.forEachBone -import dev.slimevr.skeleton.mutateCopy import dev.slimevr.util.inFloatingSeconds import dev.slimevr.util.timeSource +import io.github.axisangles.ktmath.Quaternion +import io.github.axisangles.ktmath.Vector3 import kotlin.time.ComparableTimeMark -fun computeVelocity( - currentBone: BoneState, - lastBone: BoneState, - lastTime: ComparableTimeMark, -): Velocity { - val deltaPosition = currentBone.tailPosition - lastBone.tailPosition - val deltaRotation = currentBone.rotation / lastBone.rotation - val deltaTime = (timeSource.markNow() - lastTime).inFloatingSeconds - return Velocity( - linear = deltaPosition / deltaTime, - angular = deltaRotation.toRotationVector() / deltaTime, // TODO math - ) -} - /** * Computes linear (m/s) and angular (rad/s) velocity for the bones. */ class VelocityFkProcessor : SkeletonFkProcessor { + private data class VelocityBoneData( + val rotation: Quaternion, + val tailPosition: Vector3, + ) + + private val lastVelocityBoneData: BodyPartMap = bodyPartMap() private var lastProcessTime = timeSource.markNow() - override fun process(inputSkeleton: InputSkeleton, fk: ComputedSkeleton, floorLevel: Float) { + private fun computeVelocity( + currentBone: BoneState, + lastVelocityData: VelocityBoneData, + lastTime: ComparableTimeMark, + ): Velocity { + val deltaPosition = currentBone.tailPosition - lastVelocityData.tailPosition + val deltaRotation = currentBone.rotation / lastVelocityData.rotation + val deltaTime = (timeSource.markNow() - lastTime).inFloatingSeconds + return Velocity( + linear = deltaPosition / deltaTime, + angular = deltaRotation.toRotationVector() / deltaTime, + ) + } + + override fun process(mutableInputSkeleton: InputSkeleton, fk: ComputedSkeleton, floorLevel: Float) { fk.forEachBone { part, bone -> - val velocity = computeVelocity(bone, bone, lastProcessTime) - inputSkeleton[part] = inputSkeleton[part]?.copy(velocity = velocity) + val lastVelocityData = lastVelocityBoneData[part] + if (lastVelocityData != null) { + val velocity = computeVelocity(bone, lastVelocityData, lastProcessTime) + mutableInputSkeleton[part] = mutableInputSkeleton[part]?.copy(velocity = velocity) + } + + lastVelocityBoneData[part] = VelocityBoneData(bone.rotation, bone.tailPosition) } lastProcessTime = timeSource.markNow() } diff --git a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/bone-active-link.kt b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/bone-active-link.kt index 8cb8fbfa5..0fb641dda 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/bone-active-link.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/bone-active-link.kt @@ -22,19 +22,18 @@ class BoneActiveLinkInputProcessor : SkeletonInputProcessor { BodyPart.HIP to arrayOf(BodyPart.WAIST, BodyPart.CHEST, BodyPart.UPPER_CHEST), ) - override fun process(inputSkeleton: InputSkeleton, skeletonHeight: Float) { + override fun process(mutableInputSkeleton: InputSkeleton, skeletonHeight: Float) { for ((bodyPart, sources) in linkedToSources) { - val bone = inputSkeleton[bodyPart] ?: continue + val bone = mutableInputSkeleton[bodyPart] ?: continue if (bone.isRotationActive) continue - // Only inactive inputSkeleton are written, so one written here can never become a source below + // Only inactive bones are written, so one written here can never become a source below val closestActiveBone = sources.firstNotNullOfOrNull { part -> - inputSkeleton[part]?.takeIf { it.isRotationActive } + mutableInputSkeleton[part]?.takeIf { it.isRotationActive } } ?: continue - // Writing back the rotation the bone already carries would only allocate a new BoneInput if (closestActiveBone.rotation == bone.rotation) continue - inputSkeleton[bodyPart] = bone.copy(rotation = closestActiveBone.rotation) + mutableInputSkeleton[bodyPart] = bone.copy(rotation = closestActiveBone.rotation) } } } diff --git a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/bone-direct-link.kt b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/bone-direct-link.kt index 88cf38db8..1abfbd4ac 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/bone-direct-link.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/bone-direct-link.kt @@ -48,16 +48,15 @@ class BoneDirectLinkInputProcessor : SkeletonInputProcessor { BodyPart.RIGHT_LITTLE_TOE to BodyPart.RIGHT_RING_TOE, ) - override fun process(inputSkeleton: InputSkeleton, skeletonHeight: Float) { + override fun process(mutableInputSkeleton: InputSkeleton, skeletonHeight: Float) { for ((bodyPart, source) in linkedToSource) { - val bone = inputSkeleton[bodyPart] ?: continue + val bone = mutableInputSkeleton[bodyPart] ?: continue if (bone.isRotationActive) continue - val rotation = inputSkeleton[source]?.rotation ?: continue - // Writing back the rotation the bone already carries would only allocate a new BoneInput + val rotation = mutableInputSkeleton[source]?.rotation ?: continue if (rotation == bone.rotation) continue - inputSkeleton[bodyPart] = bone.copy(rotation = rotation) + mutableInputSkeleton[bodyPart] = bone.copy(rotation = rotation) } } } diff --git a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/bone-prediction.kt b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/bone-prediction.kt index 76407032c..71ad80814 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/bone-prediction.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/bone-prediction.kt @@ -40,7 +40,7 @@ class BonePredictionInputProcessor(val settings: Settings) : SkeletonInputProces else -> 1f } - override fun process(inputSkeleton: InputSkeleton, skeletonHeight: Float) { + override fun process(mutableInputSkeleton: InputSkeleton, skeletonHeight: Float) { val config = settings.context.state.value.data.skeletonConfig.filtering if (config.type != FilteringType.PREDICTION) { // Drop stale velocities so re-enabling doesn't diff against a long outdated pose @@ -51,7 +51,7 @@ class BonePredictionInputProcessor(val settings: Settings) : SkeletonInputProces val now = timeSource.markNow() val newVelocities = bodyPartMap() - inputSkeleton.forEachBone { bodyPart, bone -> + mutableInputSkeleton.forEachBone { bodyPart, bone -> val prev = velocities[bodyPart] if (prev == null) { newVelocities[bodyPart] = BoneVelocity(bone.rotation, Quaternion.IDENTITY, now) @@ -71,7 +71,7 @@ class BonePredictionInputProcessor(val settings: Settings) : SkeletonInputProces newVelocities[bodyPart] = BoneVelocity(bone.rotation, rotationDelta, if (changed) now else prev.lastChange) val scaledDelta = Quaternion.IDENTITY.lerpR(rotationDelta, bonePredictionAmount).unit() val predicted = (scaledDelta * bone.rotation).unit() - if (predicted != bone.rotation) inputSkeleton[bodyPart] = bone.copy(rotation = predicted) + if (predicted != bone.rotation) mutableInputSkeleton[bodyPart] = bone.copy(rotation = predicted) } velocities = newVelocities } diff --git a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/bone-smoothing.kt b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/bone-smoothing.kt index ef3c61cfd..1f39520a7 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/bone-smoothing.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/bone-smoothing.kt @@ -19,7 +19,7 @@ class BoneSmoothingInputProcessor(val settings: Settings) : SkeletonInputProcess private var lastProcessTime = timeSource.markNow() // TODO this isn't linear. Do we want linear smoothing like in main? - override fun process(inputSkeleton: InputSkeleton, skeletonHeight: Float) { + override fun process(mutableInputSkeleton: InputSkeleton, skeletonHeight: Float) { val config = settings.context.state.value.data.skeletonConfig.filtering if (config.type != FilteringType.SMOOTHING) { // Drop stale poses so re-enabling doesn't blend out of an outdated frame @@ -36,11 +36,11 @@ class BoneSmoothingInputProcessor(val settings: Settings) : SkeletonInputProcess val alpha = ((1 - smoothingAmount) * lastFrameTimeSeconds * SMOOTHING_MULTIPLIER).coerceIn(0f, 1f) val newSmoothed = bodyPartMap() - inputSkeleton.forEachBone { bodyPart, bone -> + mutableInputSkeleton.forEachBone { bodyPart, bone -> val prev = smoothed[bodyPart] ?: bone.rotation val rotation = prev.lerpR(bone.rotation, alpha).unit() newSmoothed[bodyPart] = rotation - if (rotation != bone.rotation) inputSkeleton[bodyPart] = bone.copy(rotation = rotation) + if (rotation != bone.rotation) mutableInputSkeleton[bodyPart] = bone.copy(rotation = rotation) } smoothed = newSmoothed } diff --git a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/bone-yaw-fallback.kt b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/bone-yaw-fallback.kt index d23830d6d..6b8a615fa 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/bone-yaw-fallback.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/bone-yaw-fallback.kt @@ -12,20 +12,17 @@ import kotlin.collections.set * falling back to their parent's yaw. */ class BoneYawFallbackInputProcessor : SkeletonInputProcessor { - override fun process(inputSkeleton: InputSkeleton, skeletonHeight: Float) { - inputSkeleton.forEachBone { parentPart, parentBone -> + override fun process(mutableInputSkeleton: InputSkeleton, skeletonHeight: Float) { + mutableInputSkeleton.forEachBone { parentPart, parentBone -> if (!parentBone.isRotationActive) return@forEachBone // Parent needs to be active - val children = iterateBodyPartHierarchy(parentPart, true) - // Depends only on the parent, so every child below reuses it - val yaw = parentBone.rotation.project(Vector3.POS_Y).unit() - for (childPart in children) { - val childBone = inputSkeleton[childPart.second] ?: continue + val parentYaw = parentBone.rotation.project(Vector3.POS_Y).unit() + for (childPart in iterateBodyPartHierarchy(parentPart, true)) { + val childBone = mutableInputSkeleton[childPart.second] ?: continue if (childBone.isRotationActive) continue // Child needs to be inactive - // Writing back the rotation the bone already carries would only allocate a new BoneInput - if (yaw == childBone.rotation) continue + if (parentYaw == childBone.rotation) continue - inputSkeleton[childPart.second] = childBone.copy(rotation = yaw) + mutableInputSkeleton[childPart.second] = childBone.copy(rotation = parentYaw) } } } diff --git a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/finger-impute.kt b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/finger-impute.kt index f7f0d9dd1..38883751a 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/finger-impute.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/finger-impute.kt @@ -47,16 +47,15 @@ class FingerImputeInputProcessor : SkeletonInputProcessor { ) // TODO : There's more math to do here. Reference the original code. - override fun process(inputSkeleton: InputSkeleton, skeletonHeight: Float) { + override fun process(mutableInputSkeleton: InputSkeleton, skeletonHeight: Float) { for ((bodyPart, source) in fingerToSource) { - val bone = inputSkeleton[bodyPart] ?: continue + val bone = mutableInputSkeleton[bodyPart] ?: continue if (bone.isRotationActive) continue - val rotation = inputSkeleton[source]?.rotation ?: continue - // Writing back the rotation the bone already carries would only allocate a new BoneInput + val rotation = mutableInputSkeleton[source]?.rotation ?: continue if (rotation == bone.rotation) continue - inputSkeleton[bodyPart] = bone.copy(rotation = rotation) + mutableInputSkeleton[bodyPart] = bone.copy(rotation = rotation) } } } diff --git a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/head-position-fallback.kt b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/head-position-fallback.kt index 44521b24d..6d342f851 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/head-position-fallback.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/head-position-fallback.kt @@ -10,11 +10,11 @@ import solarxr_protocol.datatypes.BodyPart * Moves the head input to the skeleton height. Else, it would default to (0, 0, 0). */ class HeadPositionFallbackProcessor(val settings: Settings) : SkeletonInputProcessor { - override fun process(inputSkeleton: InputSkeleton, skeletonHeight: Float) { - val headBone = inputSkeleton[BodyPart.HEAD] ?: return + override fun process(mutableInputSkeleton: InputSkeleton, skeletonHeight: Float) { + val headBone = mutableInputSkeleton[BodyPart.HEAD] ?: return if (headBone.position != null) return // Set the head position to the be standing up at the origin - inputSkeleton[BodyPart.HEAD] = headBone.copy(position = Vector3(0f, skeletonHeight, 0f)) + mutableInputSkeleton[BodyPart.HEAD] = headBone.copy(position = Vector3(0f, skeletonHeight, 0f)) } } diff --git a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/hip-yaw-roll-align.kt b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/hip-yaw-roll-align.kt index b9a833ce0..7d93ed504 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/hip-yaw-roll-align.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/hip-yaw-roll-align.kt @@ -10,18 +10,6 @@ import solarxr_protocol.datatypes.BodyPart * Handles rotating the hip' yaw and roll to match the upper legs' yaw and roll. */ class HipYawRollAlignInputProcessor(val settings: Settings) : SkeletonInputProcessor { - override fun process(inputSkeleton: InputSkeleton, skeletonHeight: Float) { - val hipBone = inputSkeleton[BodyPart.HIP] ?: return - if (hipBone.isRotationActive) return - val leftUpperLegBone = inputSkeleton[BodyPart.LEFT_UPPER_LEG] ?: return - val rightUpperLegBone = inputSkeleton[BodyPart.RIGHT_UPPER_LEG] ?: return - - val ratio = settings.context.state.value.data.skeletonConfig.ratios.interpolateHipWithUpperLegs - val sourceRotation = leftUpperLegBone.rotation.lerpQ(rightUpperLegBone.rotation, 0.5f) - val alignedRotation = alignYawRoll(hipBone.rotation, sourceRotation) - inputSkeleton[BodyPart.HIP] = hipBone.copy(rotation = hipBone.rotation.interpQ(alignedRotation, ratio)) - } - /** * Rotates the first Quaternion to match its yaw and roll to the rotation of * the second Quaternion @@ -35,4 +23,16 @@ class HipYawRollAlignInputProcessor(val settings: Settings) : SkeletonInputProce val c = Quaternion(r.w, -r.x, 0f, 0f) return (from * r * c).unit() } + + override fun process(mutableInputSkeleton: InputSkeleton, skeletonHeight: Float) { + val hipBone = mutableInputSkeleton[BodyPart.HIP] ?: return + if (hipBone.isRotationActive) return + val leftUpperLegBone = mutableInputSkeleton[BodyPart.LEFT_UPPER_LEG] ?: return + val rightUpperLegBone = mutableInputSkeleton[BodyPart.RIGHT_UPPER_LEG] ?: return + + val ratio = settings.context.state.value.data.skeletonConfig.ratios.interpolateHipWithUpperLegs + val sourceRotation = leftUpperLegBone.rotation.lerpQ(rightUpperLegBone.rotation, 0.5f) + val alignedRotation = alignYawRoll(hipBone.rotation, sourceRotation) + mutableInputSkeleton[BodyPart.HIP] = hipBone.copy(rotation = hipBone.rotation.interpQ(alignedRotation, ratio)) + } } diff --git a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/spine-impute.kt b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/spine-impute.kt index 96e3b38b5..3d5453a1e 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/spine-impute.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/spine-impute.kt @@ -1,11 +1,15 @@ package dev.slimevr.skeleton.inputprocessors +import com.jme3.math.FastMath import dev.slimevr.config.Settings import dev.slimevr.skeleton.InputSkeleton import dev.slimevr.skeleton.SkeletonInputProcessor import io.github.axisangles.ktmath.Quaternion import solarxr_protocol.datatypes.BodyPart +// At this default value, the user's spine should behave as we meant it to. +const val DEFAULT_SPINE_RATIO = 0.5f + /** * Handles imputing the rotation of spine bones that are not actively receiving data from the rotations * of nearby bones. @@ -20,6 +24,48 @@ class SpineImputeInputProcessor(val settings: Settings) : SkeletonInputProcessor UPPER_LEGS(arrayOf(BodyPart.LEFT_UPPER_LEG, BodyPart.RIGHT_UPPER_LEG)), } + /** + * Returns the interpolation ratio modified with the reliability and curve. + * If a single bone is missing, ratio is reliability adjusted. + * At 0.0 curve, ratio is raw. + * At 0.5 curve, ratio is reliability adjusted. + * At 1.0 curve, ratio is 0 for the first in chain and 1 for the last in chain. + */ + private fun interpolateRatio(chainIndex: Int, chainSize: Int, fromUpperToLower: Float, curvature: Float, fromReliability: Float, toReliability: Float): Float { + val reliabilityAdjusted = remapRatioWithReliability(fromUpperToLower, fromReliability, toReliability) + if (chainSize <= 1) return reliabilityAdjusted // Single missing bone; reliability adjusted + + return if (curvature <= DEFAULT_SPINE_RATIO) { + // Raw to reliability adjusted + FastMath.lerp(fromUpperToLower, reliabilityAdjusted, curvature * 2f) + } else { + // Reliability adjusted to max curve + val maxCurve = chainIndex / (chainSize - 1).toFloat() + FastMath.lerp(reliabilityAdjusted, maxCurve, (curvature - DEFAULT_SPINE_RATIO) * 2f) + } + } + + /** + * Remaps a ratio This assumes a default ratio of 50%. + */ + private fun remapRatioWithReliability(ratio: Float, fromReliability: Float, toReliability: Float): Float { + val reliability = (fromReliability / toReliability) * DEFAULT_SPINE_RATIO + + return if (ratio <= DEFAULT_SPINE_RATIO) { + ratio * 2f * reliability + } else { + reliability + (ratio - DEFAULT_SPINE_RATIO) * 2f * (1f - reliability) + } + } + + private fun averageRotation(inputSkeleton: InputSkeleton, takeBodyParts: Array = arrayOf()): Quaternion { + val bonesToAverage = inputSkeleton.values.filter { it.bodyPart in takeBodyParts } + return bonesToAverage.map { it.rotation } + .reduceIndexedOrNull { index, acc, rotation -> + acc.lerpQ(rotation, 1f / (index + 1)) + } ?: Quaternion.IDENTITY + } + private fun reliabilityOf(bodyPart: BodyPart, source: SpineSource): Float = when (bodyPart) { BodyPart.WAIST -> when (source) { SpineSource.CHEST -> 0.6f @@ -36,22 +82,22 @@ class SpineImputeInputProcessor(val settings: Settings) : SkeletonInputProcessor else -> error("Invalid missing spine body part $bodyPart") } - override fun process(inputSkeleton: InputSkeleton, skeletonHeight: Float) { + override fun process(mutableInputSkeleton: InputSkeleton, skeletonHeight: Float) { val ratios = settings.context.state.value.data.skeletonConfig.ratios - val hasChest = inputSkeleton[BodyPart.UPPER_CHEST]?.isRotationActive == true || inputSkeleton[BodyPart.CHEST]?.isRotationActive == true - val hasWaist = inputSkeleton[BodyPart.WAIST]?.isRotationActive == true - val hasHip = inputSkeleton[BodyPart.HIP]?.isRotationActive == true - val hasUpperLegs = inputSkeleton[BodyPart.LEFT_UPPER_LEG]?.isRotationActive == true && inputSkeleton[BodyPart.RIGHT_UPPER_LEG]?.isRotationActive == true + val hasChest = mutableInputSkeleton[BodyPart.UPPER_CHEST]?.isRotationActive == true || mutableInputSkeleton[BodyPart.CHEST]?.isRotationActive == true + val hasWaist = mutableInputSkeleton[BodyPart.WAIST]?.isRotationActive == true + val hasHip = mutableInputSkeleton[BodyPart.HIP]?.isRotationActive == true + val hasUpperLegs = mutableInputSkeleton[BodyPart.LEFT_UPPER_LEG]?.isRotationActive == true && mutableInputSkeleton[BodyPart.RIGHT_UPPER_LEG]?.isRotationActive == true val missingSpineParts = buildList { if (!hasWaist) add(BodyPart.WAIST) if (!hasHip) add(BodyPart.HIP) } for ((chainIndex, bodyPart) in missingSpineParts.withIndex()) { - val bone = inputSkeleton[bodyPart] ?: continue + val bone = mutableInputSkeleton[bodyPart] ?: continue - // Get the first active inputSkeleton above and below this one in the chain + // Get the first active bones above and below this one in the chain val (fromSource, toSource) = when (bodyPart) { BodyPart.WAIST -> { val from = SpineSource.CHEST.takeIf { hasChest } ?: continue @@ -85,54 +131,10 @@ class SpineImputeInputProcessor(val settings: Settings) : SkeletonInputProcessor reliabilityOf(bodyPart, toSource), ) - val fromRotation = averageRotation(inputSkeleton, fromSource.parts) - val toRotation = averageRotation(inputSkeleton, toSource.parts) + val fromRotation = averageRotation(mutableInputSkeleton, fromSource.parts) + val toRotation = averageRotation(mutableInputSkeleton, toSource.parts) - inputSkeleton[bodyPart] = bone.copy(rotation = fromRotation.interpQ(toRotation, interpolateRatio)) + mutableInputSkeleton[bodyPart] = bone.copy(rotation = fromRotation.interpQ(toRotation, interpolateRatio)) } } - - /** - * Returns the interpolation ratio modified with the reliability and curve. - * If a single bone is missing, ratio is reliability adjusted. - * At 0.0 curve, ratio is raw. - * At 0.5 curve, ratio is reliability adjusted. - * At 1.0 curve, ratio is 0 for the first in chain and 1 for the last in chain. - */ - private fun interpolateRatio(chainIndex: Int, chainSize: Int, fromUpperToLower: Float, curvature: Float, fromReliability: Float, toReliability: Float): Float { - val reliabilityAdjusted = remapRatioWithReliability(fromUpperToLower, fromReliability, toReliability) - if (chainSize <= 1) return reliabilityAdjusted // Single missing bone; reliability adjusted - - return if (curvature <= 0.5f) { - // Raw to reliability adjusted - lerp(fromUpperToLower, reliabilityAdjusted, curvature * 2f) - } else { - // Reliability adjusted to max curve - val maxCurve = chainIndex / (chainSize - 1).toFloat() - lerp(reliabilityAdjusted, maxCurve, (curvature - 0.5f) * 2f) - } - } - - /** - * Remaps a ratio This assumes a default ratio of 50%. - */ - private fun remapRatioWithReliability(ratio: Float, fromReliability: Float, toReliability: Float): Float { - val reliability = (fromReliability / toReliability) * 0.5f - - return if (ratio <= 0.5f) { - ratio * 2f * reliability - } else { - reliability + (ratio - 0.5f) * 2f * (1f - reliability) - } - } - - private fun lerp(from: Float, to: Float, t: Float): Float = from + (to - from) * t - - private fun averageRotation(inputSkeleton: InputSkeleton, takeBodyParts: Array = arrayOf()): Quaternion { - val bonesToAverage = inputSkeleton.values.filter { it.bodyPart in takeBodyParts } - return bonesToAverage.map { it.rotation } - .reduceIndexedOrNull { index, acc, rotation -> - acc.lerpQ(rotation, 1f / (index + 1)) - } ?: Quaternion.IDENTITY - } } diff --git a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/upper-legs-roll-align.kt b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/upper-legs-roll-align.kt index 6d86f542c..7c03a511a 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/upper-legs-roll-align.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/upper-legs-roll-align.kt @@ -20,21 +20,6 @@ class UpperLegsRollAlignInputProcessor(val settings: Settings) : SkeletonInputPr BodyPart.RIGHT_UPPER_LEG to BodyPart.RIGHT_LOWER_LEG, ) - override fun process(inputSkeleton: InputSkeleton, skeletonHeight: Float) { - val ratio = settings.context.state.value.data.skeletonConfig.ratios.interpolateUpperLegsTwistWithLowerLegs - if (ratio == 0f) return - - // Upper legs are written, lower legs are read, so the two never overlap - for (bodyPartToSource in bodyPartToSources) { - val bone = inputSkeleton[bodyPartToSource.first] ?: continue - if (!bone.isRotationActive) continue - - val sourceRotation = inputSkeleton[bodyPartToSource.second]?.rotation ?: continue - val alignedRotation = alignRoll(bone.rotation, sourceRotation) - inputSkeleton[bodyPartToSource.first] = bone.copy(rotation = bone.rotation.interpQ(alignedRotation, ratio)) - } - } - /** * Rotates the first Quaternion to match its roll to the rotation of * the second Quaternion @@ -48,4 +33,19 @@ class UpperLegsRollAlignInputProcessor(val settings: Settings) : SkeletonInputPr val c = Quaternion(r.w, 0f, -r.y, 0f) return (to * r * c).unit() } + + override fun process(mutableInputSkeleton: InputSkeleton, skeletonHeight: Float) { + val ratio = settings.context.state.value.data.skeletonConfig.ratios.interpolateUpperLegsTwistWithLowerLegs + if (ratio == 0f) return + + // Upper legs are written, lower legs are read, so the two never overlap + for (bodyPartToSource in bodyPartToSources) { + val bone = mutableInputSkeleton[bodyPartToSource.first] ?: continue + if (!bone.isRotationActive) continue + + val sourceRotation = mutableInputSkeleton[bodyPartToSource.second]?.rotation ?: continue + val alignedRotation = alignRoll(bone.rotation, sourceRotation) + mutableInputSkeleton[bodyPartToSource.first] = bone.copy(rotation = bone.rotation.interpQ(alignedRotation, ratio)) + } + } } 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 a2a43b573..a1b13c43a 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/module.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/module.kt @@ -42,7 +42,7 @@ data class BoneInput( val isRotationActive: Boolean, val isAccelerationActive: Boolean, val isPositionActive: Boolean, - val velocity: Velocity + val velocity: Velocity, ) /** Post-FK */ @@ -54,7 +54,7 @@ data class BoneState( val acceleration: Vector3, val headPosition: Vector3, val tailPosition: Vector3, - val velocity: Velocity + val velocity: Velocity, ) { // FK rebuilds most of the skeleton every frame, so anything read less often than that is // computed on demand rather than per bone @@ -95,7 +95,7 @@ val DEFAULT_BONE_INPUT = BoneInput( isRotationActive = false, isAccelerationActive = false, isPositionActive = false, - velocity = Velocity(Vector3.NULL, Vector3.NULL) + velocity = Velocity(Vector3.NULL, Vector3.NULL), ) val DEFAULT_SKELETON_STATE = SkeletonState( @@ -158,14 +158,14 @@ sealed interface SkeletonActions { typealias SkeletonContext = Context typealias SkeletonBehaviour = Behaviour interface SkeletonInputProcessor { - fun process(inputSkeleton: InputSkeleton, skeletonHeight: Float) + fun process(mutableInputSkeleton: InputSkeleton, skeletonHeight: Float) } interface SkeletonFkProcessor { - fun process(inputSkeleton: InputSkeleton, fk: ComputedSkeleton, floorLevel: Float) + fun process(mutableInputSkeleton: InputSkeleton, fk: ComputedSkeleton, floorLevel: Float) } typealias IKTargets = BodyPartMap interface SkeletonTargetProcessor { - fun process(fk: ComputedSkeleton, ikTargets: IKTargets, floorLevel: Float): IKTargets + fun process(mutableIkTargets: IKTargets, fk: ComputedSkeleton, floorLevel: Float) } class Skeleton( diff --git a/server/core/src/main/java/dev/slimevr/skeleton/targetprocessors/floor-clip.kt b/server/core/src/main/java/dev/slimevr/skeleton/targetprocessors/floor-clip.kt index 881098aaa..8cf8c62e1 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/targetprocessors/floor-clip.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/targetprocessors/floor-clip.kt @@ -12,15 +12,14 @@ class FloorClipTargetProcessor( val settings: Settings, val bodyParts: Array = arrayOf(BodyPart.LEFT_LOWER_LEG, BodyPart.RIGHT_LOWER_LEG), ) : SkeletonTargetProcessor { - override fun process(fk: ComputedSkeleton, ikTargets: IKTargets, floorLevel: Float): IKTargets { - if (!settings.context.state.value.data.skeletonConfig.toggles.floorClip) return ikTargets + override fun process(mutableIkTargets: IKTargets, fk: ComputedSkeleton, floorLevel: Float) { + if (!settings.context.state.value.data.skeletonConfig.toggles.floorClip) return for (bodyPart in bodyParts) { // Get existing target or make a new one at the current bone position - val target = ikTargets[bodyPart] ?: fk[bodyPart]?.tailPosition ?: continue + val target = mutableIkTargets[bodyPart] ?: fk[bodyPart]?.tailPosition ?: continue // Snap the target up to the floor if it's under - ikTargets[bodyPart] = Vector3(target.x, target.y.coerceAtLeast(floorLevel), target.z) + mutableIkTargets[bodyPart] = Vector3(target.x, target.y.coerceAtLeast(floorLevel), target.z) } - return ikTargets } } diff --git a/server/core/src/main/java/dev/slimevr/skeleton/targetprocessors/skating-correction.kt b/server/core/src/main/java/dev/slimevr/skeleton/targetprocessors/skating-correction.kt index 4a81b83e5..6be46e24b 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/targetprocessors/skating-correction.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/targetprocessors/skating-correction.kt @@ -2,7 +2,6 @@ package dev.slimevr.skeleton.targetprocessors import dev.slimevr.config.Settings import dev.slimevr.skeleton.BodyPartMap -import dev.slimevr.skeleton.BoneState import dev.slimevr.skeleton.ComputedSkeleton import dev.slimevr.skeleton.IKTargets import dev.slimevr.skeleton.SkeletonTargetProcessor @@ -10,7 +9,6 @@ import dev.slimevr.skeleton.Velocity import dev.slimevr.skeleton.bodyPartMap import dev.slimevr.util.inFloatingSeconds import dev.slimevr.util.timeSource -import io.github.axisangles.ktmath.Quaternion import io.github.axisangles.ktmath.Vector3 import solarxr_protocol.datatypes.BodyPart import kotlin.time.ComparableTimeMark @@ -33,9 +31,9 @@ const val FOOT_VELOCITY_SENSITIVITY = 1f const val FOOT_ACCELERATION_SENSITIVITY = 1f const val SKATING_LOCK_ENGAGE_PERCENT = 1.1f -const val SKATING_DISTANCE_THRESHOLD = 0.5f // All squared for performance +const val SKATING_DISTANCE_THRESHOLD = 0.25f const val SKATING_LINEAR_VELOCITY_THRESHOLD = 5.76f const val SKATING_ANGULAR_VELOCITY_THRESHOLD = 20.25f const val SKATING_ACCELERATION_THRESHOLD = 0.49f @@ -60,17 +58,19 @@ val BODY_PART_MASSES = mapOf( ) // TODO Implement feet accel/velocity sensitivity calculation +// TODO check if the first line (with SKATING_DISTANCE_THRESHOLD) is correct fun shouldLock( position: Vector3, + lastPosition: Vector3, acceleration: Vector3, velocity: Velocity, thresholdMultiplier: Float, floorLevel: Float, -): Boolean = // (velocity.horizontalDistance <= SKATING_DISTANCE_THRESHOLD * thresholdMultiplier) && TODO +): Boolean = ((position - lastPosition).let { Vector3(it.x, 0f, it.z) }.lenSq() <= SKATING_DISTANCE_THRESHOLD * thresholdMultiplier) && (velocity.linear.lenSq() <= SKATING_LINEAR_VELOCITY_THRESHOLD * thresholdMultiplier) && - (velocity.angular.lenSq() <= SKATING_ANGULAR_VELOCITY_THRESHOLD * thresholdMultiplier) && - (position.y - floorLevel <= FLOOR_DISTANCE_THRESHOLD * thresholdMultiplier) && - (acceleration.lenSq() <= SKATING_ACCELERATION_THRESHOLD * thresholdMultiplier) + (velocity.angular.lenSq() <= SKATING_ANGULAR_VELOCITY_THRESHOLD * thresholdMultiplier) && + (position.y - floorLevel <= FLOOR_DISTANCE_THRESHOLD * thresholdMultiplier) && + (acceleration.lenSq() <= SKATING_ACCELERATION_THRESHOLD * thresholdMultiplier) // TODO Use this to calculate feet pressure fun centerOfMass( @@ -123,11 +123,12 @@ class SkatingCorrectionTargetProcessor(val settings: Settings) : SkeletonTargetP // Centre of mass var comState: COMState? = null + val lastLockedPositions: BodyPartMap = bodyPartMap() val lockState: BodyPartMap = bodyPartMap() - override fun process(fk: ComputedSkeleton, ikTargets: IKTargets, floorLevel: Float): IKTargets { + override fun process(mutableIkTargets: IKTargets, fk: ComputedSkeleton, floorLevel: Float) { val skeletonConfig = settings.context.state.value.data.skeletonConfig - if (!skeletonConfig.toggles.skatingCorrection) return ikTargets + if (!skeletonConfig.toggles.skatingCorrection) return val curTime = timeSource.markNow() @@ -142,12 +143,14 @@ class SkatingCorrectionTargetProcessor(val settings: Settings) : SkeletonTargetP for (bodyPart in VELOCITY_BODY_PARTS) { val curBone = fk[bodyPart] ?: continue + val curPosition = curBone.tailPosition // Consider locking BodyPart val lastState = lockState[bodyPart] val wasLocked = lastState?.locked == true val isLocked = shouldLock( - curBone.tailPosition, + curPosition, + lastLockedPositions[bodyPart] ?: curPosition, curBone.acceleration, curBone.velocity, if (wasLocked) SKATING_LOCK_ENGAGE_PERCENT else 1f, @@ -157,7 +160,7 @@ class SkatingCorrectionTargetProcessor(val settings: Settings) : SkeletonTargetP val activeState = computeLockState( wasLocked, isLocked, - curBone.tailPosition, + curPosition, )?.also { // Track lock state changes lockState[bodyPart] = it @@ -165,9 +168,9 @@ class SkatingCorrectionTargetProcessor(val settings: Settings) : SkeletonTargetP } ?: lastState ?: continue if (activeState.locked) { - ikTargets[bodyPart] = activeState.position + mutableIkTargets[bodyPart] = activeState.position + lastLockedPositions[bodyPart] = activeState.position } } - return ikTargets } } 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 71648e98a..553223727 100644 --- a/server/core/src/test/java/dev/slimevr/vmc/OutputEncoderTest.kt +++ b/server/core/src/test/java/dev/slimevr/vmc/OutputEncoderTest.kt @@ -27,7 +27,7 @@ private fun bone(bodyPart: BodyPart, rotation: Quaternion = Quaternion.IDENTITY) acceleration = Vector3.NULL, headPosition = Vector3(0f, 1f, 0f), tailPosition = Vector3(0f, 0.9f, 0f), - velocity = Velocity(Vector3.NULL, Vector3.NULL) + velocity = Velocity(Vector3.NULL, Vector3.NULL), ) private fun messages(bundle: OscBundle): List = bundle.contents.map { (it as OscContent.Message).msg }