mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-12-04 07:42:31 -08:00
Revert "Solarxr Connection Handshake and bone registry + untested but compile change for binding provider"
This reverts commit 69acb068c7.
This commit is contained in:
1 parent
f8e126efdd
commit
d69357b53b
127 files changed
+1198
-2462
No files matched your search
@@ -27,15 +27,14 @@ import dev.slimevr.routing.BoneRoutingManager
|
||||
import dev.slimevr.serial.FlashingHandler
|
||||
import dev.slimevr.serial.SerialPortHandle
|
||||
import dev.slimevr.serial.SerialServer
|
||||
import dev.slimevr.skeleton.BoneId
|
||||
import dev.slimevr.skeleton.BoneMap
|
||||
import dev.slimevr.skeleton.BoneRegistry
|
||||
import dev.slimevr.skeleton.BoneState
|
||||
import dev.slimevr.skeleton.ComputedSkeleton
|
||||
import dev.slimevr.skeleton.DEFAULT_SKELETON_STATE
|
||||
import dev.slimevr.skeleton.ProportionsBehaviour
|
||||
import dev.slimevr.skeleton.Skeleton
|
||||
import dev.slimevr.skeleton.buildBones
|
||||
import dev.slimevr.skeleton.defaultSkeletonState
|
||||
import dev.slimevr.solarxr.SolarXRBridge
|
||||
import dev.slimevr.solarxr.SolarXRBridgeState
|
||||
import dev.slimevr.solarxr.driver.DriverHandshakeBehaviour
|
||||
import dev.slimevr.solarxr.rpc.ServerInfos
|
||||
import dev.slimevr.tapdetection.TapDetectionManager
|
||||
import dev.slimevr.tracker.Motion
|
||||
@@ -105,12 +104,12 @@ fun buildTestUserConfig(scope: CoroutineScope): UserConfig {
|
||||
return userConfig
|
||||
}
|
||||
|
||||
fun buildTestSkeleton(scope: CoroutineScope, registry: BoneRegistry = BoneRegistry.standard()): Skeleton {
|
||||
fun buildTestSkeleton(scope: CoroutineScope): Skeleton {
|
||||
val context = Context.create(
|
||||
initialState = defaultSkeletonState(registry),
|
||||
initialState = DEFAULT_SKELETON_STATE,
|
||||
scope = scope,
|
||||
reducer = ::reduceSkeleton,
|
||||
behaviours = listOf(ProportionsBehaviour(buildTestUserConfig(scope), registry)),
|
||||
behaviours = listOf(ProportionsBehaviour(buildTestUserConfig(scope))),
|
||||
name = "TestSkeleton",
|
||||
)
|
||||
val computed = MutableSharedFlow<ComputedSkeleton>(
|
||||
@@ -123,11 +122,6 @@ fun buildTestSkeleton(scope: CoroutineScope, registry: BoneRegistry = BoneRegist
|
||||
return skeleton
|
||||
}
|
||||
|
||||
/** Builds a [ComputedSkeleton] from BodyPart-keyed bones, for tests that think in anatomy. */
|
||||
fun BoneRegistry.computedSkeletonOf(vararg bones: Pair<BodyPart, BoneState>): ComputedSkeleton = BoneMap.of<BoneState>(this).also { map ->
|
||||
for ((bodyPart, bone) in bones) map[requireNotNull(this[bodyPart]) { "$bodyPart is not in this registry" }] = bone
|
||||
}
|
||||
|
||||
fun buildTestResetsManager(server: VRServer, settings: Settings, scope: CoroutineScope): ResetsManager {
|
||||
val context = Context.create(
|
||||
initialState = ResetsState(
|
||||
@@ -150,8 +144,8 @@ fun buildTestTracker(
|
||||
appContext: AppContextProvider,
|
||||
settings: Settings,
|
||||
id: Int,
|
||||
boneId: BoneId? = null,
|
||||
intendedBoneId: BoneId? = null,
|
||||
bodyPart: BodyPart? = null,
|
||||
intendedBodyPart: BodyPart? = null,
|
||||
status: TrackerStatus = TrackerStatus.DISCONNECTED,
|
||||
origin: DeviceOrigin = DeviceOrigin.UDP,
|
||||
imuType: ImuType? = ImuType.BNO085,
|
||||
@@ -170,8 +164,8 @@ fun buildTestTracker(
|
||||
hardwareId = "test-$id",
|
||||
name = "Tracker $id",
|
||||
imuType = imuType,
|
||||
boneId = boneId,
|
||||
intendedBoneId = intendedBoneId,
|
||||
bodyPart = bodyPart,
|
||||
intendedBodyPart = intendedBodyPart,
|
||||
customName = null,
|
||||
sessionCalibration = sessionCalibration,
|
||||
rawRotation = rawRotation,
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package dev.slimevr.bvh
|
||||
|
||||
import dev.slimevr.config.TextFileHandle
|
||||
import dev.slimevr.skeleton.BoneRegistry
|
||||
import dev.slimevr.skeleton.boneId
|
||||
import dev.slimevr.skeleton.DEFAULT_SKELETON_STATE
|
||||
import dev.slimevr.skeleton.buildBones
|
||||
import dev.slimevr.skeleton.defaultSkeletonState
|
||||
import dev.slimevr.skeleton.mutateCopy
|
||||
import io.github.axisangles.ktmath.Vector3
|
||||
import kotlinx.coroutines.test.runTest
|
||||
@@ -14,23 +12,19 @@ import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class BvhStreamTest {
|
||||
private val registry = BoneRegistry.standard()
|
||||
private val headId = BodyPart.HEAD.boneId
|
||||
private val defaultState = defaultSkeletonState(registry)
|
||||
|
||||
@Test
|
||||
fun `close persists header and frame data`() = runTest {
|
||||
val file = InMemoryBvhFile()
|
||||
val stream = BvhStream(file)
|
||||
val initialBones = buildBones(defaultState.boneInputs)
|
||||
val initialBones = buildBones(DEFAULT_SKELETON_STATE.boneInputs)
|
||||
val firstFrame = buildBones(
|
||||
defaultState.boneInputs.mutateCopy {
|
||||
it[headId] = it.getValue(headId).copy(position = Vector3(1f, 2f, 3f))
|
||||
DEFAULT_SKELETON_STATE.boneInputs.mutateCopy {
|
||||
it[BodyPart.HEAD] = it.getValue(BodyPart.HEAD).copy(position = Vector3(1f, 2f, 3f))
|
||||
},
|
||||
)
|
||||
val secondFrame = buildBones(
|
||||
defaultState.boneInputs.mutateCopy {
|
||||
it[headId] = it.getValue(headId).copy(position = Vector3(4f, 5f, 6f))
|
||||
DEFAULT_SKELETON_STATE.boneInputs.mutateCopy {
|
||||
it[BodyPart.HEAD] = it.getValue(BodyPart.HEAD).copy(position = Vector3(4f, 5f, 6f))
|
||||
},
|
||||
)
|
||||
|
||||
@@ -51,7 +45,7 @@ class BvhStreamTest {
|
||||
fun `writeFrame after close is ignored`() = runTest {
|
||||
val file = InMemoryBvhFile()
|
||||
val stream = BvhStream(file)
|
||||
val bones = buildBones(defaultState.boneInputs)
|
||||
val bones = buildBones(DEFAULT_SKELETON_STATE.boneInputs)
|
||||
|
||||
stream.writeHeader(bones)
|
||||
stream.close()
|
||||
@@ -59,8 +53,8 @@ class BvhStreamTest {
|
||||
|
||||
stream.writeFrame(
|
||||
buildBones(
|
||||
defaultState.boneInputs.mutateCopy {
|
||||
it[headId] = it.getValue(headId).copy(position = Vector3(7f, 8f, 9f))
|
||||
DEFAULT_SKELETON_STATE.boneInputs.mutateCopy {
|
||||
it[BodyPart.HEAD] = it.getValue(BodyPart.HEAD).copy(position = Vector3(7f, 8f, 9f))
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package dev.slimevr.routing
|
||||
|
||||
import dev.slimevr.skeleton.BoneRegistry
|
||||
import dev.slimevr.solarxr.driver.DRIVER_SUPPORTED_BONES
|
||||
import dev.slimevr.vmc.VMC_SUPPORTED_BONES
|
||||
import dev.slimevr.vrcosc.VRC_OSC_SUPPORTED_BONES
|
||||
@@ -32,15 +31,12 @@ private val COMMON_CANDIDATES = setOf(
|
||||
BodyPart.RIGHT_LOWER_LEG,
|
||||
)
|
||||
|
||||
private fun routedTo(
|
||||
routes: Map<BodyPart, Set<RoutingOutput>>,
|
||||
output: RoutingOutput,
|
||||
): Set<BodyPart> = routes.filterValues { output in it }.keys
|
||||
|
||||
class AutomaticRoutesTest {
|
||||
private val registry = BoneRegistry.standard()
|
||||
|
||||
private fun routedTo(routes: Routes, output: RoutingOutput): Set<BodyPart> = routes.filterValues { output in it }.keys.mapNotNullTo(mutableSetOf(), registry::bodyPartOf)
|
||||
|
||||
private fun computeAutomaticRoutes(candidateBones: Set<BodyPart>, outputStates: OutputStates): Routes = computeAutomaticRoutes(candidateBones, outputStates, registry)
|
||||
|
||||
private fun effectiveRoutes(routes: Routes, outputStates: OutputStates): Routes = effectiveRoutes(routes, outputStates, registry)
|
||||
|
||||
@Test
|
||||
fun `the driver alone takes every bone it supports`() {
|
||||
val routes = computeAutomaticRoutes(COMMON_CANDIDATES, active(RoutingOutput.DRIVER))
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package dev.slimevr.routing
|
||||
|
||||
import dev.slimevr.config.BoneRoutingConfig
|
||||
import dev.slimevr.skeleton.BoneRegistry
|
||||
import dev.slimevr.skeleton.boneId
|
||||
import solarxr_protocol.datatypes.BodyPart
|
||||
import solarxr_protocol.rpc.RoutingOutput
|
||||
import solarxr_protocol.rpc.RoutingOutputState
|
||||
@@ -10,8 +8,6 @@ import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNull
|
||||
|
||||
private val registry = BoneRegistry.standard()
|
||||
|
||||
private fun active(vararg outputs: RoutingOutput): OutputStates = RoutingOutput.entries.associateWith {
|
||||
if (it in outputs) RoutingOutputState.ACTIVE else RoutingOutputState.INACTIVE
|
||||
}
|
||||
@@ -19,16 +15,14 @@ private fun active(vararg outputs: RoutingOutput): OutputStates = RoutingOutput.
|
||||
private val NONE_ACTIVE = active()
|
||||
private val ALL_ON = active(*RoutingOutput.entries.toTypedArray())
|
||||
|
||||
private fun routesOf(vararg pairs: Pair<BodyPart, Set<RoutingOutput>>): Routes = pairs.associate { (bodyPart, outputs) -> bodyPart.boneId to outputs }
|
||||
|
||||
private fun manualRoutesOf(manualRoutes: Map<String, Set<RoutingOutput>>?): Routes = manualRoutesAsBoneIds(manualRoutes, registry)
|
||||
private fun routesOf(vararg pairs: Pair<BodyPart, Set<RoutingOutput>>): Routes = mapOf(*pairs)
|
||||
|
||||
private val AUTO_ROUTES = routesOf(
|
||||
BodyPart.HIP to setOf(RoutingOutput.DRIVER),
|
||||
BodyPart.LEFT_FOOT to setOf(RoutingOutput.DRIVER),
|
||||
)
|
||||
|
||||
private val HAND_TABLE = routesOf(BodyPart.LEFT_HAND to setOf(RoutingOutput.DRIVER))
|
||||
private val HAND_TABLE = mapOf(BodyPart.LEFT_HAND to setOf(RoutingOutput.DRIVER))
|
||||
|
||||
class ManualRoutesTest {
|
||||
@Test
|
||||
@@ -37,11 +31,11 @@ class ManualRoutesTest {
|
||||
BodyPart.HIP to setOf(RoutingOutput.DRIVER, RoutingOutput.VRC_OSC, RoutingOutput.VMC),
|
||||
)
|
||||
|
||||
val sanitized = effectiveRoutes(routes, active(RoutingOutput.DRIVER, RoutingOutput.VRC_OSC, RoutingOutput.VMC), registry)
|
||||
val sanitized = effectiveRoutes(routes, active(RoutingOutput.DRIVER, RoutingOutput.VRC_OSC, RoutingOutput.VMC))
|
||||
|
||||
assertEquals(
|
||||
setOf(RoutingOutput.DRIVER, RoutingOutput.VRC_OSC, RoutingOutput.VMC),
|
||||
sanitized[BodyPart.HIP.boneId],
|
||||
sanitized[BodyPart.HIP],
|
||||
)
|
||||
}
|
||||
|
||||
@@ -49,25 +43,25 @@ class ManualRoutesTest {
|
||||
fun `an unavailable output is dropped even when explicitly routed`() {
|
||||
val routes = routesOf(BodyPart.HIP to setOf(RoutingOutput.DRIVER, RoutingOutput.VRC_OSC))
|
||||
|
||||
val sanitized = effectiveRoutes(routes, active(RoutingOutput.VRC_OSC), registry)
|
||||
val sanitized = effectiveRoutes(routes, active(RoutingOutput.VRC_OSC))
|
||||
|
||||
assertEquals(setOf(RoutingOutput.VRC_OSC), sanitized[BodyPart.HIP.boneId])
|
||||
assertEquals(setOf(RoutingOutput.VRC_OSC), sanitized[BodyPart.HIP])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an output that cannot take the bone is dropped`() {
|
||||
val routes = routesOf(BodyPart.NECK to setOf(RoutingOutput.VRC_OSC, RoutingOutput.VMC))
|
||||
|
||||
val sanitized = effectiveRoutes(routes, active(RoutingOutput.DRIVER, RoutingOutput.VRC_OSC, RoutingOutput.VMC), registry)
|
||||
val sanitized = effectiveRoutes(routes, active(RoutingOutput.DRIVER, RoutingOutput.VRC_OSC, RoutingOutput.VMC))
|
||||
|
||||
assertEquals(setOf(RoutingOutput.VMC), sanitized[BodyPart.NECK.boneId])
|
||||
assertEquals(setOf(RoutingOutput.VMC), sanitized[BodyPart.NECK])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a bone left with no output is not kept`() {
|
||||
val routes = routesOf(BodyPart.HIP to setOf(RoutingOutput.VRC_OSC))
|
||||
|
||||
assertEquals(emptyMap(), effectiveRoutes(routes, NONE_ACTIVE, registry))
|
||||
assertEquals(emptyMap(), effectiveRoutes(routes, NONE_ACTIVE))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +78,7 @@ class RoutingChangeTest {
|
||||
fun `switching to manual the first time starts from an empty table`() {
|
||||
val config = BoneRoutingConfig(automatic = true, manualRoutes = null)
|
||||
|
||||
val next = applyRoutingChange(config, automatic = false, routes = AUTO_ROUTES, registry = registry)
|
||||
val next = applyRoutingChange(config, automatic = false, routes = AUTO_ROUTES)
|
||||
|
||||
assertEquals(false, next.automatic)
|
||||
assertEquals(emptyMap(), next.manualRoutes.orEmpty())
|
||||
@@ -93,38 +87,38 @@ class RoutingChangeTest {
|
||||
@Test
|
||||
fun `switching to manual again keeps the table the user built`() {
|
||||
val built = routesOf(BodyPart.HIP to setOf(RoutingOutput.VRC_OSC))
|
||||
val config = BoneRoutingConfig(automatic = true, manualRoutes = built.toManualRoutesConfig(registry))
|
||||
val config = BoneRoutingConfig(automatic = true, manualRoutes = built)
|
||||
|
||||
val next = applyRoutingChange(config, automatic = false, routes = AUTO_ROUTES, registry = registry)
|
||||
val next = applyRoutingChange(config, automatic = false, routes = AUTO_ROUTES)
|
||||
|
||||
assertEquals(built, manualRoutesOf(next.manualRoutes))
|
||||
assertEquals(built, next.manualRoutes)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `editing while manual stores the new table`() {
|
||||
val config = BoneRoutingConfig(automatic = false, manualRoutes = HAND_TABLE.toManualRoutesConfig(registry))
|
||||
val edited = routesOf(BodyPart.HIP to setOf(RoutingOutput.VRC_OSC))
|
||||
val config = BoneRoutingConfig(automatic = false, manualRoutes = HAND_TABLE)
|
||||
val edited = mapOf(BodyPart.HIP to setOf(RoutingOutput.VRC_OSC))
|
||||
|
||||
val next = applyRoutingChange(config, automatic = false, routes = edited, registry = registry)
|
||||
val next = applyRoutingChange(config, automatic = false, routes = edited)
|
||||
|
||||
assertEquals(edited, manualRoutesOf(next.manualRoutes))
|
||||
assertEquals(edited, next.manualRoutes)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `switching back to automatic keeps the manual table`() {
|
||||
val config = BoneRoutingConfig(automatic = false, manualRoutes = HAND_TABLE.toManualRoutesConfig(registry))
|
||||
val config = BoneRoutingConfig(automatic = false, manualRoutes = HAND_TABLE)
|
||||
|
||||
val next = applyRoutingChange(config, automatic = true, routes = emptyMap(), registry = registry)
|
||||
val next = applyRoutingChange(config, automatic = true, routes = emptyMap())
|
||||
|
||||
assertEquals(true, next.automatic)
|
||||
assertEquals(HAND_TABLE, manualRoutesOf(next.manualRoutes))
|
||||
assertEquals(HAND_TABLE, next.manualRoutes)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `staying automatic never creates a manual table`() {
|
||||
val config = BoneRoutingConfig(automatic = true, manualRoutes = null)
|
||||
|
||||
val next = applyRoutingChange(config, automatic = true, routes = AUTO_ROUTES, registry = registry)
|
||||
val next = applyRoutingChange(config, automatic = true, routes = AUTO_ROUTES)
|
||||
|
||||
assertEquals(emptyMap(), next.manualRoutes)
|
||||
}
|
||||
@@ -134,12 +128,12 @@ class RoutingChangeTest {
|
||||
var config = BoneRoutingConfig(automatic = true, manualRoutes = null)
|
||||
val built = AUTO_ROUTES + HAND_TABLE
|
||||
|
||||
config = applyRoutingChange(config, automatic = false, routes = emptyMap(), registry = registry)
|
||||
config = applyRoutingChange(config, automatic = false, routes = built, registry = registry)
|
||||
config = applyRoutingChange(config, automatic = true, routes = emptyMap(), registry = registry)
|
||||
config = applyRoutingChange(config, automatic = false, routes = emptyMap(), registry = registry)
|
||||
config = applyRoutingChange(config, automatic = false, routes = emptyMap())
|
||||
config = applyRoutingChange(config, automatic = false, routes = built)
|
||||
config = applyRoutingChange(config, automatic = true, routes = emptyMap())
|
||||
config = applyRoutingChange(config, automatic = false, routes = emptyMap())
|
||||
|
||||
assertEquals(built, manualRoutesOf(config.manualRoutes))
|
||||
assertEquals(built, config.manualRoutes)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,11 +143,10 @@ class ForcedRoutesTest {
|
||||
val config = applyRoutingChange(
|
||||
BoneRoutingConfig(automatic = false, manualRoutes = emptyMap()),
|
||||
automatic = false,
|
||||
routes = routesOf(BodyPart.HIP to setOf(RoutingOutput.DRIVER, RoutingOutput.VMC)),
|
||||
registry = registry,
|
||||
routes = mapOf(BodyPart.HIP to setOf(RoutingOutput.DRIVER, RoutingOutput.VMC)),
|
||||
)
|
||||
|
||||
assertEquals(routesOf(BodyPart.HIP to setOf(RoutingOutput.DRIVER)), manualRoutesOf(config.manualRoutes))
|
||||
assertEquals(mapOf(BodyPart.HIP to setOf(RoutingOutput.DRIVER)), config.manualRoutes)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -161,8 +154,7 @@ class ForcedRoutesTest {
|
||||
val config = applyRoutingChange(
|
||||
BoneRoutingConfig(automatic = false, manualRoutes = emptyMap()),
|
||||
automatic = false,
|
||||
routes = routesOf(BodyPart.NECK to setOf(RoutingOutput.VMC)),
|
||||
registry = registry,
|
||||
routes = mapOf(BodyPart.NECK to setOf(RoutingOutput.VMC)),
|
||||
)
|
||||
|
||||
assertEquals(emptyMap(), config.manualRoutes)
|
||||
@@ -172,44 +164,43 @@ class ForcedRoutesTest {
|
||||
fun `required bones come back when the routes are resolved`() {
|
||||
val config = BoneRoutingConfig(
|
||||
automatic = false,
|
||||
manualRoutes = routesOf(BodyPart.HIP to setOf(RoutingOutput.DRIVER)).toManualRoutesConfig(registry),
|
||||
manualRoutes = mapOf(BodyPart.HIP to setOf(RoutingOutput.DRIVER)),
|
||||
)
|
||||
|
||||
val resolved = effectiveRoutes(
|
||||
manualRoutesOf(config.manualRoutes),
|
||||
config.manualRoutes.orEmpty(),
|
||||
active(RoutingOutput.DRIVER, RoutingOutput.VMC),
|
||||
registry,
|
||||
)
|
||||
|
||||
assertEquals(setOf(RoutingOutput.DRIVER, RoutingOutput.VMC), resolved[BodyPart.HIP.boneId])
|
||||
assertEquals(setOf(RoutingOutput.VMC), resolved[BodyPart.NECK.boneId])
|
||||
assertEquals(setOf(RoutingOutput.DRIVER, RoutingOutput.VMC), resolved[BodyPart.HIP])
|
||||
assertEquals(setOf(RoutingOutput.VMC), resolved[BodyPart.NECK])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an inactive output does not force anything`() {
|
||||
val config = BoneRoutingConfig(automatic = false, manualRoutes = emptyMap())
|
||||
|
||||
val resolved = effectiveRoutes(manualRoutesOf(config.manualRoutes), active(RoutingOutput.DRIVER), registry)
|
||||
val resolved = effectiveRoutes(config.manualRoutes.orEmpty(), active(RoutingOutput.DRIVER))
|
||||
|
||||
assertEquals(emptyMap(), resolved)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the page shows required bones ticked whatever is stored`() {
|
||||
val shown = effectiveRoutes(emptyMap(), ALL_ON, registry)
|
||||
val shown = effectiveRoutes(emptyMap(), ALL_ON)
|
||||
|
||||
assertEquals(setOf(RoutingOutput.VMC), shown[BodyPart.NECK.boneId])
|
||||
assertEquals(setOf(RoutingOutput.VMC), shown[BodyPart.NECK])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `automatic gets required bones through the same step as manual`() {
|
||||
val states = active(RoutingOutput.DRIVER, RoutingOutput.VMC)
|
||||
|
||||
val automatic = effectiveRoutes(computeAutomaticRoutes(setOf(BodyPart.HIP), states, registry), states, registry)
|
||||
val manual = effectiveRoutes(routesOf(BodyPart.HIP to setOf(RoutingOutput.DRIVER)), states, registry)
|
||||
val automatic = effectiveRoutes(computeAutomaticRoutes(setOf(BodyPart.HIP), states), states)
|
||||
val manual = effectiveRoutes(mapOf(BodyPart.HIP to setOf(RoutingOutput.DRIVER)), states)
|
||||
|
||||
assertEquals(automatic[BodyPart.NECK.boneId], manual[BodyPart.NECK.boneId])
|
||||
assertEquals(automatic[BodyPart.HIP.boneId], manual[BodyPart.HIP.boneId])
|
||||
assertEquals(automatic[BodyPart.NECK], manual[BodyPart.NECK])
|
||||
assertEquals(automatic[BodyPart.HIP], manual[BodyPart.HIP])
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -233,25 +224,25 @@ class OverrideRoutesTest {
|
||||
fun `automatic routes no hands on its own`() {
|
||||
val candidates = determineCandidateBones(setOf(BodyPart.LEFT_HAND, BodyPart.HIP))
|
||||
|
||||
val routes = computeAutomaticRoutes(candidates, ALL_ON, registry)
|
||||
val routes = computeAutomaticRoutes(candidates, ALL_ON)
|
||||
|
||||
assertNull(routes[BodyPart.LEFT_HAND.boneId])
|
||||
assertNull(routes[BodyPart.LEFT_HAND])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an override routes the hand while automatic`() {
|
||||
val config = BoneRoutingConfig(automatic = true, manualRoutes = HAND_TABLE.toManualRoutesConfig(registry))
|
||||
val config = BoneRoutingConfig(automatic = true, manualRoutes = HAND_TABLE)
|
||||
|
||||
val routes = computeAutomaticRoutes(determineCandidateBones(emptySet()), ALL_ON, registry) + overrideRoutes(config, registry)
|
||||
val routes = computeAutomaticRoutes(determineCandidateBones(emptySet()), ALL_ON) + overrideRoutes(config)
|
||||
|
||||
assertEquals(setOf(RoutingOutput.DRIVER), routes[BodyPart.LEFT_HAND.boneId])
|
||||
assertEquals(setOf(RoutingOutput.DRIVER), routes[BodyPart.LEFT_HAND])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `only the overridable bones of a stored table count as overrides`() {
|
||||
val config = BoneRoutingConfig(automatic = true, manualRoutes = (AUTO_ROUTES + HAND_TABLE).toManualRoutesConfig(registry))
|
||||
val config = BoneRoutingConfig(automatic = true, manualRoutes = AUTO_ROUTES + HAND_TABLE)
|
||||
|
||||
assertEquals(HAND_TABLE, overrideRoutes(config, registry))
|
||||
assertEquals(HAND_TABLE, overrideRoutes(config))
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -261,8 +252,7 @@ class OverrideRoutesTest {
|
||||
val next = applyRoutingChange(
|
||||
config,
|
||||
automatic = true,
|
||||
routes = routesOf(BodyPart.LEFT_HAND to setOf(RoutingOutput.VMC)),
|
||||
registry = registry,
|
||||
routes = mapOf(BodyPart.LEFT_HAND to setOf(RoutingOutput.VMC)),
|
||||
)
|
||||
|
||||
assertEquals(emptyMap(), next.manualRoutes)
|
||||
@@ -272,26 +262,26 @@ class OverrideRoutesTest {
|
||||
fun `editing while automatic stores the override and nothing else`() {
|
||||
val config = BoneRoutingConfig(automatic = true, manualRoutes = null)
|
||||
|
||||
val next = applyRoutingChange(config, automatic = true, routes = AUTO_ROUTES + HAND_TABLE, registry = registry)
|
||||
val next = applyRoutingChange(config, automatic = true, routes = AUTO_ROUTES + HAND_TABLE)
|
||||
|
||||
assertEquals(HAND_TABLE, manualRoutesOf(next.manualRoutes))
|
||||
assertEquals(HAND_TABLE, next.manualRoutes)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `editing while automatic leaves a stored manual table alone`() {
|
||||
val stored = routesOf(BodyPart.HIP to setOf(RoutingOutput.VRC_OSC))
|
||||
val config = BoneRoutingConfig(automatic = true, manualRoutes = stored.toManualRoutesConfig(registry))
|
||||
val config = BoneRoutingConfig(automatic = true, manualRoutes = stored)
|
||||
|
||||
val next = applyRoutingChange(config, automatic = true, routes = HAND_TABLE, registry = registry)
|
||||
val next = applyRoutingChange(config, automatic = true, routes = HAND_TABLE)
|
||||
|
||||
assertEquals(stored + HAND_TABLE, manualRoutesOf(next.manualRoutes))
|
||||
assertEquals(stored + HAND_TABLE, next.manualRoutes)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `dropping the hand from the request clears the override`() {
|
||||
val config = BoneRoutingConfig(automatic = true, manualRoutes = HAND_TABLE.toManualRoutesConfig(registry))
|
||||
val config = BoneRoutingConfig(automatic = true, manualRoutes = HAND_TABLE)
|
||||
|
||||
val next = applyRoutingChange(config, automatic = true, routes = AUTO_ROUTES, registry = registry)
|
||||
val next = applyRoutingChange(config, automatic = true, routes = AUTO_ROUTES)
|
||||
|
||||
assertEquals(emptyMap(), next.manualRoutes)
|
||||
}
|
||||
@@ -300,10 +290,10 @@ class OverrideRoutesTest {
|
||||
fun `the override survives a round trip through manual`() {
|
||||
var config = BoneRoutingConfig(automatic = true, manualRoutes = null)
|
||||
|
||||
config = applyRoutingChange(config, automatic = true, routes = HAND_TABLE, registry = registry)
|
||||
config = applyRoutingChange(config, automatic = false, routes = emptyMap(), registry = registry)
|
||||
config = applyRoutingChange(config, automatic = true, routes = emptyMap(), registry = registry)
|
||||
config = applyRoutingChange(config, automatic = true, routes = HAND_TABLE)
|
||||
config = applyRoutingChange(config, automatic = false, routes = emptyMap())
|
||||
config = applyRoutingChange(config, automatic = true, routes = emptyMap())
|
||||
|
||||
assertEquals(setOf(RoutingOutput.DRIVER), overrideRoutes(config, registry)[BodyPart.LEFT_HAND.boneId])
|
||||
assertEquals(setOf(RoutingOutput.DRIVER), overrideRoutes(config)[BodyPart.LEFT_HAND])
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package dev.slimevr.skeleton
|
||||
|
||||
import solarxr_protocol.datatypes.BodyPart
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertSame
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
/**
|
||||
* [iterateBodyPartHierarchy] returns a traversal derived once at class init rather than walked per
|
||||
* call. That is only safe while the cached result matches a fresh walk of [BODY_PART_HIERARCHY_MAP],
|
||||
* so this pins the two together: order included, since [buildBones] relies on a parent being visited
|
||||
* before its children.
|
||||
*/
|
||||
class BodyPartHierarchyTest {
|
||||
|
||||
private fun walk(root: BodyPart, onlyChildren: Boolean): List<Pair<BodyPart?, BodyPart>> {
|
||||
val expected = mutableListOf<Pair<BodyPart?, BodyPart>>()
|
||||
fun visit(parent: BodyPart?, bone: BodyPart, skipSelf: Boolean) {
|
||||
if (!skipSelf) expected += parent to bone
|
||||
for (child in BODY_PART_HIERARCHY_MAP[bone] ?: return) visit(bone, child, false)
|
||||
}
|
||||
visit(null, root, onlyChildren)
|
||||
return expected
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `cached traversal matches a fresh walk for every root`() {
|
||||
for (root in BodyPart.entries) {
|
||||
for (onlyChildren in listOf(false, true)) {
|
||||
assertEquals(
|
||||
walk(root, onlyChildren),
|
||||
iterateBodyPartHierarchy(root, onlyChildren),
|
||||
"traversal drifted for root=$root onlyChildren=$onlyChildren",
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `every bone is visited after its parent`() {
|
||||
val seen = mutableSetOf<BodyPart>()
|
||||
for ((parent, bone) in iterateBodyPartHierarchy()) {
|
||||
if (parent != null) {
|
||||
assertTrue(parent in seen, "$bone was visited before its parent $parent")
|
||||
}
|
||||
seen += bone
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `repeated calls hand back the same instance`() {
|
||||
assertSame(
|
||||
iterateBodyPartHierarchy(BodyPart.LEFT_HAND, true),
|
||||
iterateBodyPartHierarchy(BodyPart.LEFT_HAND, true),
|
||||
"the traversal is meant to be derived once, not rebuilt per call",
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,188 +0,0 @@
|
||||
package dev.slimevr.skeleton
|
||||
|
||||
import solarxr_protocol.connection.BoneDefinition
|
||||
import solarxr_protocol.datatypes.BodyPart
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
import kotlin.test.assertNotNull
|
||||
import kotlin.test.assertNull
|
||||
import kotlin.test.assertSame
|
||||
import kotlin.test.assertTrue
|
||||
import solarxr_protocol.connection.BoneRegistry as WireBoneRegistry
|
||||
|
||||
class BoneRegistryTest {
|
||||
private val registry = BoneRegistry.standard()
|
||||
|
||||
@Test
|
||||
fun `standard registry resolves every standardized body part`() {
|
||||
for (bodyPart in BodyPart.entries) {
|
||||
if (bodyPart == BodyPart.NONE) continue
|
||||
val id = assertNotNull(registry[bodyPart], "Expected an ID for $bodyPart")
|
||||
assertEquals(bodyPart, registry.bodyPartOf(id))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `unknown ID resolves to no definition`() {
|
||||
assertNull(registry[BoneId(0xdeadu)])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `accepts a multi-level parent chain`() {
|
||||
val registry = BoneRegistry.from(
|
||||
WireBoneRegistry(
|
||||
bones = listOf(
|
||||
BoneDefinition(1u, "a", null, 0u, null),
|
||||
BoneDefinition(2u, "b", null, 1u, null),
|
||||
BoneDefinition(3u, "c", null, 2u, null),
|
||||
),
|
||||
),
|
||||
)
|
||||
assertNotNull(registry[BoneId(3u)])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `rejects duplicate IDs`() {
|
||||
assertFailsWith<IllegalArgumentException> {
|
||||
BoneRegistry.from(
|
||||
WireBoneRegistry(
|
||||
bones = listOf(
|
||||
BoneDefinition(1u, "a", null, 0u, null),
|
||||
BoneDefinition(1u, "b", null, 0u, null),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `rejects ID 0`() {
|
||||
assertFailsWith<IllegalArgumentException> {
|
||||
BoneRegistry.from(
|
||||
WireBoneRegistry(
|
||||
bones = listOf(BoneDefinition(0u, "a", null, 0u, null)),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `rejects an unknown parent`() {
|
||||
assertFailsWith<IllegalArgumentException> {
|
||||
BoneRegistry.from(
|
||||
WireBoneRegistry(
|
||||
bones = listOf(BoneDefinition(1u, "a", null, 2u, null)),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `rejects a cycle`() {
|
||||
assertFailsWith<IllegalArgumentException> {
|
||||
BoneRegistry.from(
|
||||
WireBoneRegistry(
|
||||
bones = listOf(
|
||||
BoneDefinition(1u, "a", null, 2u, null),
|
||||
BoneDefinition(2u, "b", null, 1u, null),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `rejects a bone that is its own parent`() {
|
||||
assertFailsWith<IllegalArgumentException> {
|
||||
BoneRegistry.from(
|
||||
WireBoneRegistry(
|
||||
bones = listOf(BoneDefinition(1u, "a", null, 1u, null)),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `rejects duplicate standard body parts`() {
|
||||
assertFailsWith<IllegalArgumentException> {
|
||||
BoneRegistry.from(
|
||||
WireBoneRegistry(
|
||||
bones = listOf(
|
||||
BoneDefinition(1u, "a", null, 0u, BodyPart.HIP),
|
||||
BoneDefinition(2u, "b", null, 0u, BodyPart.HIP),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `rejects non-contiguous IDs`() {
|
||||
assertFailsWith<IllegalArgumentException> {
|
||||
BoneRegistry.from(
|
||||
WireBoneRegistry(
|
||||
bones = listOf(
|
||||
BoneDefinition(1u, "a", null, 0u, null),
|
||||
BoneDefinition(3u, "b", null, 0u, null),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [BoneRegistry.hierarchyFrom] returns a traversal cached lazily per registry rather than walked
|
||||
* every call. That is only safe while the cached result matches a fresh walk of
|
||||
* [BODY_PART_HIERARCHY_MAP], so this pins the two together: order included, since [buildBones]
|
||||
* relies on a parent being visited before its children.
|
||||
*/
|
||||
private fun walk(root: BodyPart, onlyChildren: Boolean): List<Pair<BodyPart?, BodyPart>> {
|
||||
val expected = mutableListOf<Pair<BodyPart?, BodyPart>>()
|
||||
fun visit(parent: BodyPart?, bone: BodyPart, skipSelf: Boolean) {
|
||||
if (!skipSelf) expected += parent to bone
|
||||
for (child in BODY_PART_HIERARCHY_MAP[bone] ?: return) visit(bone, child, false)
|
||||
}
|
||||
visit(null, root, onlyChildren)
|
||||
return expected
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `cached traversal matches a fresh walk for every root`() {
|
||||
for (root in BodyPart.entries) {
|
||||
if (root == BodyPart.NONE) continue
|
||||
val rootId = requireNotNull(registry[root])
|
||||
for (onlyChildren in listOf(false, true)) {
|
||||
val actual = registry.hierarchyFrom(rootId, onlyChildren)
|
||||
.map { (parentId, boneId) -> parentId?.let { registry.bodyPartOf(it) } to requireNotNull(registry.bodyPartOf(boneId)) }
|
||||
assertEquals(
|
||||
walk(root, onlyChildren),
|
||||
actual,
|
||||
"traversal drifted for root=$root onlyChildren=$onlyChildren",
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `every bone is visited after its parent`() {
|
||||
val seen = mutableSetOf<BoneId>()
|
||||
val headId = requireNotNull(registry[BodyPart.HEAD])
|
||||
for ((parent, boneId) in registry.hierarchyFrom(headId)) {
|
||||
if (parent != null) {
|
||||
assertTrue(parent in seen, "$boneId was visited before its parent $parent")
|
||||
}
|
||||
seen += boneId
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `repeated calls hand back the same instance`() {
|
||||
val leftHandId = requireNotNull(registry[BodyPart.LEFT_HAND])
|
||||
assertSame(
|
||||
registry.hierarchyFrom(leftHandId, true),
|
||||
registry.hierarchyFrom(leftHandId, true),
|
||||
"the traversal is meant to be derived once, not rebuilt per call",
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -9,31 +9,29 @@ import kotlin.test.Test
|
||||
class IKTest {
|
||||
@Test
|
||||
fun testCcdIk() {
|
||||
val registry = BoneRegistry.standard()
|
||||
|
||||
val boneInputs: InputSkeleton = BoneMap.of(registry)
|
||||
boneInputs[BodyPart.NECK.boneId] = DEFAULT_BONE_INPUT.copy(
|
||||
boneId = BodyPart.NECK.boneId,
|
||||
val boneInputs: InputSkeleton = bodyPartMap()
|
||||
boneInputs[BodyPart.NECK] = DEFAULT_BONE_INPUT.copy(
|
||||
bodyPart = BodyPart.NECK,
|
||||
offset = Vector3.NEG_Y,
|
||||
)
|
||||
boneInputs[BodyPart.UPPER_CHEST.boneId] = DEFAULT_BONE_INPUT.copy(
|
||||
boneId = BodyPart.UPPER_CHEST.boneId,
|
||||
boneInputs[BodyPart.UPPER_CHEST] = DEFAULT_BONE_INPUT.copy(
|
||||
bodyPart = BodyPart.UPPER_CHEST,
|
||||
offset = Vector3.NEG_Y,
|
||||
)
|
||||
boneInputs[BodyPart.LOWER_CHEST.boneId] = DEFAULT_BONE_INPUT.copy(
|
||||
boneId = BodyPart.LOWER_CHEST.boneId,
|
||||
boneInputs[BodyPart.LOWER_CHEST] = DEFAULT_BONE_INPUT.copy(
|
||||
bodyPart = BodyPart.LOWER_CHEST,
|
||||
offset = Vector3.NEG_Y,
|
||||
)
|
||||
boneInputs[BodyPart.UPPER_WAIST.boneId] = DEFAULT_BONE_INPUT.copy(
|
||||
boneId = BodyPart.UPPER_WAIST.boneId,
|
||||
boneInputs[BodyPart.UPPER_WAIST] = DEFAULT_BONE_INPUT.copy(
|
||||
bodyPart = BodyPart.UPPER_WAIST,
|
||||
offset = Vector3.NEG_Y,
|
||||
)
|
||||
boneInputs[BodyPart.LOWER_WAIST.boneId] = DEFAULT_BONE_INPUT.copy(
|
||||
boneId = BodyPart.LOWER_WAIST.boneId,
|
||||
boneInputs[BodyPart.LOWER_WAIST] = DEFAULT_BONE_INPUT.copy(
|
||||
bodyPart = BodyPart.LOWER_WAIST,
|
||||
offset = Vector3.NEG_Y,
|
||||
)
|
||||
boneInputs[BodyPart.HIP.boneId] = DEFAULT_BONE_INPUT.copy(
|
||||
boneId = BodyPart.HIP.boneId,
|
||||
boneInputs[BodyPart.HIP] = DEFAULT_BONE_INPUT.copy(
|
||||
bodyPart = BodyPart.HIP,
|
||||
offset = Vector3.NEG_Y,
|
||||
)
|
||||
|
||||
@@ -41,20 +39,20 @@ class IKTest {
|
||||
val target = Vector3.POS_X * 3f
|
||||
val goal = IKChainGoal(
|
||||
listOf(
|
||||
BodyPart.NECK.boneId,
|
||||
BodyPart.UPPER_CHEST.boneId,
|
||||
BodyPart.LOWER_CHEST.boneId,
|
||||
BodyPart.UPPER_WAIST.boneId,
|
||||
BodyPart.LOWER_WAIST.boneId,
|
||||
BodyPart.HIP.boneId,
|
||||
BodyPart.NECK,
|
||||
BodyPart.UPPER_CHEST,
|
||||
BodyPart.LOWER_CHEST,
|
||||
BodyPart.UPPER_WAIST,
|
||||
BodyPart.LOWER_WAIST,
|
||||
BodyPart.HIP,
|
||||
),
|
||||
target,
|
||||
)
|
||||
|
||||
val ikOut = ccdIk(boneInputs, bones, listOf(goal), BODY_PART_CONSTRAINT_MAP.resolveToBoneIds(), 0.01f, 100)
|
||||
val ikOut = ccdIk(boneInputs, bones, listOf(goal), BODY_PART_CONSTRAINT_MAP, 0.01f, 100)
|
||||
assert(ikOut.goalsReached.all { it.value }) {
|
||||
val boneRots = ikOut.bones.values.joinToString {
|
||||
"${it.boneId}: ${it.rotation.toEulerAngles(EulerOrder.YZX)}"
|
||||
"${it.bodyPart}: ${it.rotation.toEulerAngles(EulerOrder.YZX)}"
|
||||
}
|
||||
val targetDist = chainDistanceFromTarget(ikOut.bones, goal.chain, goal.target)
|
||||
"Failed to reach target:\nDistance from target: $targetDist\nBone rotations: $boneRots"
|
||||
|
||||
@@ -1,162 +0,0 @@
|
||||
package dev.slimevr.solarxr
|
||||
|
||||
import com.google.flatbuffers.FlatBufferBuilder
|
||||
import dev.slimevr.EventDispatcher
|
||||
import dev.slimevr.TestAppContext
|
||||
import dev.slimevr.buildTestSkeleton
|
||||
import dev.slimevr.buildTestVrServer
|
||||
import dev.slimevr.context.Context
|
||||
import dev.slimevr.fbscodegen.runtime.JvmFlatBufferWriter
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.test.TestScope
|
||||
import kotlinx.coroutines.test.runCurrent
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import solarxr_protocol.ClientHello
|
||||
import solarxr_protocol.HelloStatus
|
||||
import solarxr_protocol.MessageBundle
|
||||
import solarxr_protocol.ServerHello
|
||||
import solarxr_protocol.connection.BoneDefinition
|
||||
import solarxr_protocol.connection.BoneRegistry
|
||||
import solarxr_protocol.connection.ConfigurationAcknowledged
|
||||
import solarxr_protocol.connection.ConnectionError
|
||||
import solarxr_protocol.connection.ConnectionErrorCode
|
||||
import solarxr_protocol.connection.ConnectionMessageHeader
|
||||
import solarxr_protocol.data_feed.DataFeedMessageHeader
|
||||
import solarxr_protocol.data_feed.StartDataFeed
|
||||
import java.nio.ByteBuffer
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
private fun TestScope.buildTestBridge(sent: MutableList<MessageBundle>): SolarXRBridge {
|
||||
val appContext = object : TestAppContext() {
|
||||
override val server = buildTestVrServer(backgroundScope)
|
||||
override val skeleton = buildTestSkeleton(backgroundScope)
|
||||
}
|
||||
val context = Context.create(
|
||||
initialState = SolarXRBridgeState(),
|
||||
scope = backgroundScope,
|
||||
reducer = ::reduce,
|
||||
name = "ConnectionInitTest",
|
||||
)
|
||||
val bridge = SolarXRBridge(
|
||||
id = 1,
|
||||
context = context,
|
||||
appContext = appContext,
|
||||
dataFeedDispatcher = EventDispatcher("test.datafeed", backgroundScope),
|
||||
rpcDispatcher = EventDispatcher("test.rpc", backgroundScope),
|
||||
driverDispatcher = EventDispatcher("test.driver", backgroundScope),
|
||||
)
|
||||
bridge.outbound.on<MessageBundle> { sent += it }.launchIn(backgroundScope)
|
||||
runCurrent()
|
||||
return bridge
|
||||
}
|
||||
|
||||
private fun MessageBundle.singleConnectionError(): ConnectionError = connectionMsgs?.single()?.message as? ConnectionError ?: error("Expected a single ConnectionError")
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
class ConnectionInitTest {
|
||||
|
||||
@Test
|
||||
fun `checkedSolarXRFrame rejects a wrong identifier`() {
|
||||
val fbb = FlatBufferBuilder(64)
|
||||
ClientHello(protocolVersion = SOLARXR_PROTOCOL_VERSION).finish(JvmFlatBufferWriter(fbb))
|
||||
assertFailsWith<IllegalArgumentException> {
|
||||
checkedSolarXRFrame(fbb.dataBuffer(), ServerHello.FILE_IDENTIFIER)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `checkedSolarXRFrame rejects a truncated frame`() {
|
||||
assertFailsWith<IllegalArgumentException> {
|
||||
checkedSolarXRFrame(ByteBuffer.allocate(4), ClientHello.FILE_IDENTIFIER)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `checkedSolarXRFrame rejects an oversized frame`() {
|
||||
assertFailsWith<IllegalArgumentException> {
|
||||
checkedSolarXRFrame(ByteBuffer.allocate(SOLARXR_MAX_FRAME_SIZE + 1), ClientHello.FILE_IDENTIFIER)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ClientHello, ServerHello and MessageBundle round-trip with their identifiers`() {
|
||||
val helloFbb = FlatBufferBuilder(64)
|
||||
ClientHello(protocolVersion = SOLARXR_PROTOCOL_VERSION).finish(JvmFlatBufferWriter(helloFbb))
|
||||
val helloReader = checkedSolarXRFrame(helloFbb.dataBuffer(), ClientHello.FILE_IDENTIFIER)
|
||||
assertTrue(ClientHello.hasIdentifier(helloReader))
|
||||
assertEquals(SOLARXR_PROTOCOL_VERSION, ClientHello.fromByteBuffer(helloReader).protocolVersion)
|
||||
|
||||
val replyFbb = FlatBufferBuilder(64)
|
||||
ServerHello(HelloStatus.ACCEPTED, SOLARXR_PROTOCOL_VERSION).finish(JvmFlatBufferWriter(replyFbb))
|
||||
val replyReader = checkedSolarXRFrame(replyFbb.dataBuffer(), ServerHello.FILE_IDENTIFIER)
|
||||
assertTrue(ServerHello.hasIdentifier(replyReader))
|
||||
assertEquals(HelloStatus.ACCEPTED, ServerHello.fromByteBuffer(replyReader).status)
|
||||
|
||||
val bundleFbb = FlatBufferBuilder(64)
|
||||
MessageBundle(connectionMsgs = listOf(ConnectionMessageHeader(ConfigurationAcknowledged())))
|
||||
.finish(JvmFlatBufferWriter(bundleFbb))
|
||||
val bundleReader = checkedSolarXRFrame(bundleFbb.dataBuffer(), MessageBundle.FILE_IDENTIFIER)
|
||||
assertTrue(MessageBundle.hasIdentifier(bundleReader))
|
||||
assertTrue(MessageBundle.fromByteBuffer(bundleReader).connectionMsgs?.single()?.message is ConfigurationAcknowledged)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `application bundles are rejected before configuration completes`() = runTest {
|
||||
val sent = mutableListOf<MessageBundle>()
|
||||
val bridge = buildTestBridge(sent)
|
||||
var dispatched = false
|
||||
bridge.dataFeedDispatcher.on<StartDataFeed> { dispatched = true }.launchIn(backgroundScope)
|
||||
runCurrent()
|
||||
|
||||
onSolarXRMessage(
|
||||
MessageBundle(dataFeedMsgs = listOf(DataFeedMessageHeader(message = StartDataFeed(dataFeeds = emptyList())))),
|
||||
bridge,
|
||||
)
|
||||
runCurrent()
|
||||
|
||||
assertFalse(dispatched)
|
||||
assertEquals(ConnectionErrorCode.INITIALIZATION_REQUIRED, sent.single().singleConnectionError().code)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `application bundles dispatch once configuration completes`() = runTest {
|
||||
val sent = mutableListOf<MessageBundle>()
|
||||
val bridge = buildTestBridge(sent)
|
||||
var dispatched = false
|
||||
bridge.dataFeedDispatcher.on<StartDataFeed> { dispatched = true }.launchIn(backgroundScope)
|
||||
runCurrent()
|
||||
|
||||
onSolarXRMessage(MessageBundle(connectionMsgs = listOf(ConnectionMessageHeader(ConfigurationAcknowledged()))), bridge)
|
||||
runCurrent()
|
||||
assertTrue(bridge.isReady)
|
||||
|
||||
onSolarXRMessage(
|
||||
MessageBundle(dataFeedMsgs = listOf(DataFeedMessageHeader(message = StartDataFeed(dataFeeds = emptyList())))),
|
||||
bridge,
|
||||
)
|
||||
runCurrent()
|
||||
|
||||
assertTrue(dispatched)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a client-sent bone registry is silently ignored`() = runTest {
|
||||
val sent = mutableListOf<MessageBundle>()
|
||||
val bridge = buildTestBridge(sent)
|
||||
|
||||
val clientRegistry = BoneRegistry(
|
||||
bones = listOf(BoneDefinition(1u, "x", null, 0u, null)),
|
||||
)
|
||||
onSolarXRMessage(MessageBundle(connectionMsgs = listOf(ConnectionMessageHeader(clientRegistry))), bridge)
|
||||
runCurrent()
|
||||
|
||||
assertTrue(sent.isEmpty())
|
||||
// The registry stays the server-issued default; the client's attempt never lands.
|
||||
assertEquals(dev.slimevr.skeleton.BoneRegistry.standard().value, bridge.registry.value)
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import dev.slimevr.buildTestSkeleton
|
||||
import dev.slimevr.buildTestUserConfig
|
||||
import dev.slimevr.buildTestVrServer
|
||||
import dev.slimevr.context.Context
|
||||
import dev.slimevr.skeleton.BoneId
|
||||
import dev.slimevr.solarxr.datafeed.DataFeedInitBehaviour
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.test.TestScope
|
||||
@@ -18,17 +17,13 @@ import kotlinx.coroutines.test.runCurrent
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import solarxr_protocol.MessageBundle
|
||||
import solarxr_protocol.data_feed.DataFeedConfig
|
||||
import solarxr_protocol.data_feed.DataFeedUpdate
|
||||
import solarxr_protocol.data_feed.PollDataFeed
|
||||
import solarxr_protocol.data_feed.StartDataFeed
|
||||
import solarxr_protocol.datatypes.BodyPart
|
||||
import solarxr_protocol.datatypes.BoneMask
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
private fun TestScope.testConn(onSend: suspend (MessageBundle) -> Unit): SolarXRBridge {
|
||||
private fun TestScope.testConn(onSend: suspend (ByteArray) -> Unit): SolarXRBridge {
|
||||
val server = buildTestVrServer(backgroundScope)
|
||||
val skeleton = buildTestSkeleton(backgroundScope)
|
||||
val settings = buildTestSettings(backgroundScope)
|
||||
@@ -56,7 +51,7 @@ private fun TestScope.testConn(onSend: suspend (MessageBundle) -> Unit): SolarXR
|
||||
rpcDispatcher = EventDispatcher("test.rpc", backgroundScope),
|
||||
)
|
||||
bridge.startObserving()
|
||||
bridge.outbound.on<MessageBundle> { onSend(it) }.launchIn(backgroundScope)
|
||||
bridge.outbound.on<MessageBundle> { onSend(ByteArray(0)) }.launchIn(backgroundScope)
|
||||
|
||||
// launchIn registers the handler synchronously, but the dispatcher's own drain loop still has to
|
||||
// start before anything emitted here can reach it.
|
||||
@@ -137,22 +132,5 @@ class DataFeedTest {
|
||||
assertEquals(0, sendCount)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `emitted bones carry the registry ID for their body part`() = runTest {
|
||||
val bundles = mutableListOf<MessageBundle>()
|
||||
val conn = testConn { bundles += it }
|
||||
val boneMask = BoneMask(boneLength = true)
|
||||
|
||||
conn.dataFeedDispatcher.emit(PollDataFeed(config = config(100).copy(boneMask = boneMask)))
|
||||
advanceTimeBy(1)
|
||||
|
||||
val bones = (bundles.single().dataFeedMsgs?.single()?.message as DataFeedUpdate).bones
|
||||
assertTrue(!bones.isNullOrEmpty())
|
||||
|
||||
val hipId = requireNotNull(conn.registry[BodyPart.HIP])
|
||||
assertTrue(bones.any { it.id == hipId.value })
|
||||
bones.forEach { bone -> assertTrue(conn.registry[BoneId(bone.id)] != null) }
|
||||
}
|
||||
|
||||
// TODO: need more tests for the content of a datafeed + check if the masks work
|
||||
}
|
||||
@@ -3,8 +3,6 @@ package dev.slimevr.stayaligned
|
||||
import dev.slimevr.config.StayAlignedConfig
|
||||
import dev.slimevr.config.StayAlignedRelaxedPoseConfig
|
||||
import dev.slimevr.math.angle.Angle
|
||||
import dev.slimevr.skeleton.BoneRegistry
|
||||
import dev.slimevr.skeleton.boneId
|
||||
import dev.slimevr.tracker.Motion
|
||||
import dev.slimevr.tracker.Tracker
|
||||
import dev.slimevr.tracker.stayaligned.TrackerYawCorrection
|
||||
@@ -24,8 +22,6 @@ import kotlin.test.assertNull
|
||||
*/
|
||||
class ComputeYawCorrectionTest {
|
||||
|
||||
val registry = BoneRegistry.standard()
|
||||
|
||||
val enabledStayAlignedConfig = StayAlignedConfig(
|
||||
enabled = true,
|
||||
standingRelaxedPose = StayAlignedRelaxedPoseConfig(true),
|
||||
@@ -50,7 +46,7 @@ class ComputeYawCorrectionTest {
|
||||
|
||||
val lockedTrackerState = Tracker.DEFAULT_STATE.copy(
|
||||
motion = Motion.RESTING,
|
||||
boneId = BodyPart.HIP.boneId,
|
||||
bodyPart = BodyPart.HIP,
|
||||
status = TrackerStatus.OK,
|
||||
stayAlignedData = Tracker.DEFAULT_STATE.stayAlignedData.copy(lockedRotation = pointFiveYaw),
|
||||
)
|
||||
@@ -68,7 +64,6 @@ class ComputeYawCorrectionTest {
|
||||
listOf(lockedTrackerState),
|
||||
Angle(0.002f),
|
||||
enabledStayAlignedConfig,
|
||||
registry,
|
||||
)
|
||||
|
||||
assertNotNull(result)
|
||||
@@ -82,7 +77,6 @@ class ComputeYawCorrectionTest {
|
||||
listOf(lockedTrackerState),
|
||||
Angle(0f),
|
||||
enabledStayAlignedConfig,
|
||||
registry,
|
||||
)
|
||||
|
||||
assertNotNull(result)
|
||||
@@ -96,7 +90,6 @@ class ComputeYawCorrectionTest {
|
||||
listOf(primarilyAtRestTrackerState),
|
||||
Angle(0.002f),
|
||||
enabledStayAlignedConfig,
|
||||
registry,
|
||||
)
|
||||
|
||||
assertNull(result)
|
||||
@@ -108,14 +101,13 @@ class ComputeYawCorrectionTest {
|
||||
movingTrackerState,
|
||||
listOf(
|
||||
movingTrackerState,
|
||||
movingTrackerState.copy(boneId = BodyPart.LEFT_UPPER_LEG.boneId, rotation = fiveYaw),
|
||||
movingTrackerState.copy(boneId = BodyPart.RIGHT_UPPER_LEG.boneId, rotation = fiveYaw),
|
||||
movingTrackerState.copy(boneId = BodyPart.LEFT_LOWER_LEG.boneId, rotation = fiveYaw),
|
||||
movingTrackerState.copy(boneId = BodyPart.RIGHT_LOWER_LEG.boneId, rotation = fiveYaw),
|
||||
movingTrackerState.copy(bodyPart = BodyPart.LEFT_UPPER_LEG, rotation = fiveYaw),
|
||||
movingTrackerState.copy(bodyPart = BodyPart.RIGHT_UPPER_LEG, rotation = fiveYaw),
|
||||
movingTrackerState.copy(bodyPart = BodyPart.LEFT_LOWER_LEG, rotation = fiveYaw),
|
||||
movingTrackerState.copy(bodyPart = BodyPart.RIGHT_LOWER_LEG, rotation = fiveYaw),
|
||||
),
|
||||
Angle(0.002f),
|
||||
enabledStayAlignedConfig,
|
||||
registry,
|
||||
)
|
||||
|
||||
assertNotNull(result)
|
||||
|
||||
@@ -8,7 +8,6 @@ import dev.slimevr.buildTestTracker
|
||||
import dev.slimevr.buildTestVrServerStub
|
||||
import dev.slimevr.degreeToRadian
|
||||
import dev.slimevr.quaternionAssertEquals
|
||||
import dev.slimevr.skeleton.boneId
|
||||
import dev.slimevr.tracker.behaviours.TrackerYawResetSmoothingBehaviour
|
||||
import io.github.axisangles.ktmath.Quaternion
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@@ -35,7 +34,7 @@ class YawResetSmoothingTest {
|
||||
appContext,
|
||||
settings,
|
||||
id = 0,
|
||||
boneId = BodyPart.LOWER_CHEST.boneId,
|
||||
bodyPart = BodyPart.LOWER_CHEST,
|
||||
status = TrackerStatus.OK,
|
||||
rawRotation = raw,
|
||||
additionalBehaviours = listOf(TrackerYawResetSmoothingBehaviour()),
|
||||
|
||||
@@ -15,7 +15,6 @@ import dev.slimevr.resets.ResetBodyParts
|
||||
import dev.slimevr.resets.ResetsActions
|
||||
import dev.slimevr.resets.ResetsManager
|
||||
import dev.slimevr.routing.BoneRoutingManager
|
||||
import dev.slimevr.skeleton.boneId
|
||||
import dev.slimevr.tracker.Tracker
|
||||
import dev.slimevr.tracker.TrackerActions
|
||||
import io.github.axisangles.ktmath.Vector3
|
||||
@@ -87,8 +86,8 @@ class TrackingChecklistTest {
|
||||
appContext,
|
||||
settings,
|
||||
id = id,
|
||||
boneId = bodyPart?.boneId,
|
||||
intendedBoneId = intendedBodyPart?.boneId,
|
||||
bodyPart = bodyPart,
|
||||
intendedBodyPart = intendedBodyPart,
|
||||
status = status,
|
||||
origin = origin,
|
||||
imuType = imuType,
|
||||
@@ -125,7 +124,7 @@ class TrackingChecklistTest {
|
||||
assertEquals(true, h.step(TrackingChecklistStepId.FULL_RESET).valid)
|
||||
|
||||
// Reassigning the tracker flags it again
|
||||
tracker.context.dispatch(TrackerActions.Update { copy(boneId = BodyPart.HIP.boneId) })
|
||||
tracker.context.dispatch(TrackerActions.Update { copy(bodyPart = BodyPart.HIP) })
|
||||
runCurrent()
|
||||
assertEquals(false, h.step(TrackingChecklistStepId.FULL_RESET).valid)
|
||||
}
|
||||
@@ -179,7 +178,7 @@ class TrackingChecklistTest {
|
||||
assertEquals(true, h.step(TrackingChecklistStepId.MOUNTING_CALIBRATION).enabled)
|
||||
assertEquals(false, h.step(TrackingChecklistStepId.MOUNTING_CALIBRATION).valid)
|
||||
|
||||
h.resetsManager.context.dispatch(ResetsActions.EndReset(ResetType.POSE_MOUNTING, boneIds = null))
|
||||
h.resetsManager.context.dispatch(ResetsActions.EndReset(ResetType.POSE_MOUNTING, bodyParts = null))
|
||||
runCurrent()
|
||||
assertEquals(true, h.step(TrackingChecklistStepId.MOUNTING_CALIBRATION).valid)
|
||||
}
|
||||
@@ -193,7 +192,7 @@ class TrackingChecklistTest {
|
||||
assertEquals(true, h.step(TrackingChecklistStepId.FEET_MOUNTING_CALIBRATION).enabled)
|
||||
assertEquals(false, h.step(TrackingChecklistStepId.FEET_MOUNTING_CALIBRATION).valid)
|
||||
|
||||
h.resetsManager.context.dispatch(ResetsActions.EndReset(ResetType.POSE_MOUNTING, boneIds = ResetBodyParts.FEET.map { it.boneId }))
|
||||
h.resetsManager.context.dispatch(ResetsActions.EndReset(ResetType.POSE_MOUNTING, bodyParts = ResetBodyParts.FEET.toList()))
|
||||
runCurrent()
|
||||
assertEquals(true, h.step(TrackingChecklistStepId.FEET_MOUNTING_CALIBRATION).valid)
|
||||
}
|
||||
@@ -217,7 +216,7 @@ class TrackingChecklistTest {
|
||||
assertEquals(true, h.step(TrackingChecklistStepId.UNASSIGNED_HMD).enabled)
|
||||
assertEquals(false, h.step(TrackingChecklistStepId.UNASSIGNED_HMD).valid)
|
||||
|
||||
hmd.context.dispatch(TrackerActions.Update { copy(boneId = BodyPart.HEAD.boneId) })
|
||||
hmd.context.dispatch(TrackerActions.Update { copy(bodyPart = BodyPart.HEAD) })
|
||||
runCurrent()
|
||||
assertEquals(true, h.step(TrackingChecklistStepId.UNASSIGNED_HMD).valid)
|
||||
}
|
||||
@@ -286,7 +285,7 @@ class TrackingChecklistTest {
|
||||
fun `STEAMVR_HANDS_ENABLED is disabled without a driver`() = runTest {
|
||||
val step = SteamVRHandsCheckBehaviour.computeStep(
|
||||
trackers = emptyList(),
|
||||
routes = mapOf(BodyPart.LEFT_HAND.boneId to setOf(RoutingOutput.DRIVER), BodyPart.RIGHT_HAND.boneId to setOf(RoutingOutput.DRIVER)),
|
||||
routes = mapOf(BodyPart.LEFT_HAND to setOf(RoutingOutput.DRIVER), BodyPart.RIGHT_HAND to setOf(RoutingOutput.DRIVER)),
|
||||
driverConnected = false,
|
||||
)
|
||||
|
||||
@@ -296,8 +295,8 @@ class TrackingChecklistTest {
|
||||
@Test
|
||||
fun `STEAMVR_HANDS_ENABLED flags hands sent to the driver while a controller is held`() = runTest {
|
||||
val step = SteamVRHandsCheckBehaviour.computeStep(
|
||||
trackers = listOf(checklistTracker(Tracker.DEFAULT_STATE.copy(boneId = BodyPart.LEFT_HAND.boneId, origin = DeviceOrigin.UDP)), checklistTracker(Tracker.DEFAULT_STATE.copy(boneId = BodyPart.LEFT_HAND.boneId, origin = DeviceOrigin.DRIVER))),
|
||||
routes = mapOf(BodyPart.LEFT_HAND.boneId to setOf(RoutingOutput.DRIVER), BodyPart.RIGHT_HAND.boneId to setOf(RoutingOutput.DRIVER)),
|
||||
trackers = listOf(checklistTracker(Tracker.DEFAULT_STATE.copy(bodyPart = BodyPart.LEFT_HAND, origin = DeviceOrigin.UDP)), checklistTracker(Tracker.DEFAULT_STATE.copy(bodyPart = BodyPart.LEFT_HAND, origin = DeviceOrigin.DRIVER))),
|
||||
routes = mapOf(BodyPart.LEFT_HAND to setOf(RoutingOutput.DRIVER), BodyPart.RIGHT_HAND to setOf(RoutingOutput.DRIVER)),
|
||||
driverConnected = true,
|
||||
)
|
||||
|
||||
@@ -309,7 +308,7 @@ class TrackingChecklistTest {
|
||||
fun `STEAMVR_HANDS_ENABLED flags hands sent to the driver with no hand tracker worn`() = runTest {
|
||||
val step = SteamVRHandsCheckBehaviour.computeStep(
|
||||
trackers = emptyList(),
|
||||
routes = mapOf(BodyPart.LEFT_HAND.boneId to setOf(RoutingOutput.DRIVER), BodyPart.RIGHT_HAND.boneId to setOf(RoutingOutput.DRIVER)),
|
||||
routes = mapOf(BodyPart.LEFT_HAND to setOf(RoutingOutput.DRIVER), BodyPart.RIGHT_HAND to setOf(RoutingOutput.DRIVER)),
|
||||
driverConnected = true,
|
||||
)
|
||||
|
||||
@@ -321,8 +320,8 @@ class TrackingChecklistTest {
|
||||
@Test
|
||||
fun `STEAMVR_HANDS_ENABLED accepts hand trackers when no controller is held`() = runTest {
|
||||
val step = SteamVRHandsCheckBehaviour.computeStep(
|
||||
trackers = listOf(checklistTracker(Tracker.DEFAULT_STATE.copy(boneId = BodyPart.LEFT_HAND.boneId, origin = DeviceOrigin.UDP))),
|
||||
routes = mapOf(BodyPart.LEFT_HAND.boneId to setOf(RoutingOutput.DRIVER), BodyPart.RIGHT_HAND.boneId to setOf(RoutingOutput.DRIVER)),
|
||||
trackers = listOf(checklistTracker(Tracker.DEFAULT_STATE.copy(bodyPart = BodyPart.LEFT_HAND, origin = DeviceOrigin.UDP))),
|
||||
routes = mapOf(BodyPart.LEFT_HAND to setOf(RoutingOutput.DRIVER), BodyPart.RIGHT_HAND to setOf(RoutingOutput.DRIVER)),
|
||||
driverConnected = true,
|
||||
)
|
||||
|
||||
@@ -332,7 +331,7 @@ class TrackingChecklistTest {
|
||||
@Test
|
||||
fun `STEAMVR_HANDS_ENABLED ignores hands that are not routed to the driver`() = runTest {
|
||||
val step = SteamVRHandsCheckBehaviour.computeStep(
|
||||
trackers = listOf(checklistTracker(Tracker.DEFAULT_STATE.copy(boneId = BodyPart.LEFT_HAND.boneId, origin = DeviceOrigin.UDP)), checklistTracker(Tracker.DEFAULT_STATE.copy(boneId = BodyPart.LEFT_HAND.boneId, origin = DeviceOrigin.DRIVER))),
|
||||
trackers = listOf(checklistTracker(Tracker.DEFAULT_STATE.copy(bodyPart = BodyPart.LEFT_HAND, origin = DeviceOrigin.UDP)), checklistTracker(Tracker.DEFAULT_STATE.copy(bodyPart = BodyPart.LEFT_HAND, origin = DeviceOrigin.DRIVER))),
|
||||
routes = emptyMap(),
|
||||
driverConnected = true,
|
||||
)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package dev.slimevr.vmc
|
||||
|
||||
import dev.slimevr.computedSkeletonOf
|
||||
import dev.slimevr.config.VMCConfig
|
||||
import dev.slimevr.osc.OscArg
|
||||
import dev.slimevr.osc.OscBundle
|
||||
@@ -9,11 +8,9 @@ import dev.slimevr.osc.OscMessage
|
||||
import dev.slimevr.osc.forEachOscMessage
|
||||
import dev.slimevr.quaternionApproxEqual
|
||||
import dev.slimevr.skeleton.BodyPartMap
|
||||
import dev.slimevr.skeleton.BoneRegistry
|
||||
import dev.slimevr.skeleton.BoneState
|
||||
import dev.slimevr.skeleton.Velocity
|
||||
import dev.slimevr.skeleton.bodyPartMap
|
||||
import dev.slimevr.skeleton.boneId
|
||||
import dev.slimevr.vectorAssertEquals
|
||||
import io.github.axisangles.ktmath.Quaternion
|
||||
import io.github.axisangles.ktmath.Vector3
|
||||
@@ -35,11 +32,9 @@ private fun assertApprox(expected: Quaternion, actual: Quaternion, message: Stri
|
||||
)
|
||||
}
|
||||
|
||||
private val registry = BoneRegistry.standard()
|
||||
|
||||
private fun bone(bodyPart: BodyPart, rotation: Quaternion = Quaternion.IDENTITY, headPosition: Vector3 = Vector3.ZERO) = BoneState(
|
||||
parentBone = null,
|
||||
boneId = bodyPart.boneId,
|
||||
bodyPart = bodyPart,
|
||||
headOffset = Vector3.ZERO,
|
||||
offset = Vector3(0f, -0.1f, 0f),
|
||||
rotation = rotation,
|
||||
@@ -126,24 +121,25 @@ class InputDecoderTest {
|
||||
val chestRotation = Quaternion.rotationAroundYAxis(0.4f)
|
||||
val chestHead = Vector3(0f, 0.3f, 0f)
|
||||
|
||||
val bonesByPart = mapOf(
|
||||
BodyPart.HIP to bone(BodyPart.HIP, Quaternion.rotationAroundYAxis(0.1f), Vector3.ZERO),
|
||||
BodyPart.UPPER_WAIST to bone(BodyPart.UPPER_WAIST, Quaternion.rotationAroundXAxis(0.2f), Vector3(0f, 0.15f, 0f)),
|
||||
BodyPart.LOWER_CHEST to bone(BodyPart.LOWER_CHEST, chestRotation, chestHead),
|
||||
BodyPart.UPPER_CHEST to bone(BodyPart.UPPER_CHEST, chestRotation, chestHead),
|
||||
BodyPart.NECK to bone(BodyPart.NECK, Quaternion.rotationAroundZAxis(0.15f), Vector3(0f, 0.5f, 0f)),
|
||||
BodyPart.HEAD to bone(BodyPart.HEAD, Quaternion.rotationAroundXAxis(-0.1f), Vector3(0f, 0.65f, 0f)),
|
||||
BodyPart.LEFT_SHOULDER to bone(BodyPart.LEFT_SHOULDER, Quaternion.rotationAroundZAxis(0.05f), Vector3(0.05f, 0.45f, 0f)),
|
||||
BodyPart.LEFT_UPPER_ARM to bone(BodyPart.LEFT_UPPER_ARM, Quaternion.rotationAroundZAxis(0.7f), Vector3(0.15f, 0.45f, 0f)),
|
||||
BodyPart.LEFT_LOWER_ARM to bone(BodyPart.LEFT_LOWER_ARM, Quaternion.rotationAroundXAxis(0.9f), Vector3(0.4f, 0.45f, 0f)),
|
||||
BodyPart.LEFT_HAND to bone(BodyPart.LEFT_HAND, Quaternion.rotationAroundYAxis(0.2f), Vector3(0.65f, 0.45f, 0f)),
|
||||
BodyPart.LEFT_UPPER_LEG to bone(BodyPart.LEFT_UPPER_LEG, Quaternion.rotationAroundXAxis(0.5f), Vector3(0.1f, 0f, 0f)),
|
||||
BodyPart.LEFT_LOWER_LEG to bone(BodyPart.LEFT_LOWER_LEG, Quaternion.rotationAroundXAxis(-0.3f), Vector3(0.1f, -0.4f, 0f)),
|
||||
BodyPart.LEFT_FOOT to bone(BodyPart.LEFT_FOOT, Quaternion.rotationAroundYAxis(0.25f), Vector3(0.1f, -0.8f, 0f)),
|
||||
val bones = BodyPartMap(
|
||||
mapOf(
|
||||
BodyPart.HIP to bone(BodyPart.HIP, Quaternion.rotationAroundYAxis(0.1f), Vector3.ZERO),
|
||||
BodyPart.UPPER_WAIST to bone(BodyPart.UPPER_WAIST, Quaternion.rotationAroundXAxis(0.2f), Vector3(0f, 0.15f, 0f)),
|
||||
BodyPart.LOWER_CHEST to bone(BodyPart.LOWER_CHEST, chestRotation, chestHead),
|
||||
BodyPart.UPPER_CHEST to bone(BodyPart.UPPER_CHEST, chestRotation, chestHead),
|
||||
BodyPart.NECK to bone(BodyPart.NECK, Quaternion.rotationAroundZAxis(0.15f), Vector3(0f, 0.5f, 0f)),
|
||||
BodyPart.HEAD to bone(BodyPart.HEAD, Quaternion.rotationAroundXAxis(-0.1f), Vector3(0f, 0.65f, 0f)),
|
||||
BodyPart.LEFT_SHOULDER to bone(BodyPart.LEFT_SHOULDER, Quaternion.rotationAroundZAxis(0.05f), Vector3(0.05f, 0.45f, 0f)),
|
||||
BodyPart.LEFT_UPPER_ARM to bone(BodyPart.LEFT_UPPER_ARM, Quaternion.rotationAroundZAxis(0.7f), Vector3(0.15f, 0.45f, 0f)),
|
||||
BodyPart.LEFT_LOWER_ARM to bone(BodyPart.LEFT_LOWER_ARM, Quaternion.rotationAroundXAxis(0.9f), Vector3(0.4f, 0.45f, 0f)),
|
||||
BodyPart.LEFT_HAND to bone(BodyPart.LEFT_HAND, Quaternion.rotationAroundYAxis(0.2f), Vector3(0.65f, 0.45f, 0f)),
|
||||
BodyPart.LEFT_UPPER_LEG to bone(BodyPart.LEFT_UPPER_LEG, Quaternion.rotationAroundXAxis(0.5f), Vector3(0.1f, 0f, 0f)),
|
||||
BodyPart.LEFT_LOWER_LEG to bone(BodyPart.LEFT_LOWER_LEG, Quaternion.rotationAroundXAxis(-0.3f), Vector3(0.1f, -0.4f, 0f)),
|
||||
BodyPart.LEFT_FOOT to bone(BodyPart.LEFT_FOOT, Quaternion.rotationAroundYAxis(0.25f), Vector3(0.1f, -0.8f, 0f)),
|
||||
),
|
||||
)
|
||||
val bones = registry.computedSkeletonOf(*bonesByPart.toList().toTypedArray())
|
||||
|
||||
val bundle = buildOutgoingBundle(bones, bonesByPart.keys, VMCConfig(), vrm = null, elapsed = 0.seconds)
|
||||
val bundle = buildOutgoingBundle(bones, bones.keys, VMCConfig(), vrm = null, elapsed = 0.seconds)
|
||||
val frame = decodeVmcBundle(bundle, emptyVmcInputFrame())
|
||||
val worldTransforms = vmcWorldTransforms(
|
||||
locals = frame.boneLocalRotations,
|
||||
@@ -153,7 +149,7 @@ class InputDecoderTest {
|
||||
scale = 1f,
|
||||
)
|
||||
|
||||
for ((bodyPart, originalBone) in bonesByPart) {
|
||||
for ((bodyPart, originalBone) in bones) {
|
||||
val recovered = assertNotNull(worldTransforms[bodyPart], "missing $bodyPart")
|
||||
assertApprox(originalBone.rotation, recovered.rotation, "$bodyPart rotation")
|
||||
assertApprox(originalBone.headPosition, recovered.position, "$bodyPart position")
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
package dev.slimevr.vmc
|
||||
|
||||
import dev.slimevr.computedSkeletonOf
|
||||
import dev.slimevr.config.VMCConfig
|
||||
import dev.slimevr.osc.OscArg
|
||||
import dev.slimevr.osc.OscBundle
|
||||
import dev.slimevr.osc.OscContent
|
||||
import dev.slimevr.osc.OscMessage
|
||||
import dev.slimevr.skeleton.BoneMap
|
||||
import dev.slimevr.skeleton.BoneRegistry
|
||||
import dev.slimevr.skeleton.BodyPartMap
|
||||
import dev.slimevr.skeleton.BoneState
|
||||
import dev.slimevr.skeleton.Velocity
|
||||
import dev.slimevr.skeleton.boneId
|
||||
import dev.slimevr.skeleton.bodyPartMap
|
||||
import io.github.axisangles.ktmath.Quaternion
|
||||
import io.github.axisangles.ktmath.Vector3
|
||||
import solarxr_protocol.datatypes.BodyPart
|
||||
@@ -21,11 +19,9 @@ import kotlin.test.assertNull
|
||||
import kotlin.test.assertTrue
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
private val registry = BoneRegistry.standard()
|
||||
|
||||
private fun bone(bodyPart: BodyPart, rotation: Quaternion = Quaternion.IDENTITY) = BoneState(
|
||||
parentBone = null,
|
||||
boneId = bodyPart.boneId,
|
||||
bodyPart = bodyPart,
|
||||
headOffset = Vector3.ZERO,
|
||||
offset = Vector3(0f, -0.1f, 0f),
|
||||
rotation = rotation,
|
||||
@@ -46,7 +42,7 @@ class OutputEncoderTest {
|
||||
@Test
|
||||
fun testAlwaysSendsTimeAndOkAndRoot() {
|
||||
val bundle = buildOutgoingBundle(
|
||||
bones = BoneMap.of(registry),
|
||||
bones = bodyPartMap(),
|
||||
routedBones = emptySet(),
|
||||
config = defaultConfig,
|
||||
vrm = null,
|
||||
@@ -61,9 +57,11 @@ class OutputEncoderTest {
|
||||
|
||||
@Test
|
||||
fun testSkipsBonesThatAreNotRouted() {
|
||||
val bones = registry.computedSkeletonOf(
|
||||
BodyPart.HIP to bone(BodyPart.HIP),
|
||||
BodyPart.LOWER_WAIST to bone(BodyPart.LOWER_WAIST),
|
||||
val bones = BodyPartMap(
|
||||
mapOf(
|
||||
BodyPart.HIP to bone(BodyPart.HIP),
|
||||
BodyPart.LOWER_WAIST to bone(BodyPart.LOWER_WAIST),
|
||||
),
|
||||
)
|
||||
|
||||
val bundle = buildOutgoingBundle(
|
||||
@@ -81,7 +79,7 @@ class OutputEncoderTest {
|
||||
@Test
|
||||
fun testSkipsRoutedBonesMissingFromTheSkeleton() {
|
||||
val bundle = buildOutgoingBundle(
|
||||
bones = registry.computedSkeletonOf(BodyPart.HIP to bone(BodyPart.HIP)),
|
||||
bones = BodyPartMap(mapOf(BodyPart.HIP to bone(BodyPart.HIP))),
|
||||
routedBones = setOf(BodyPart.HIP, BodyPart.LOWER_WAIST),
|
||||
config = defaultConfig,
|
||||
vrm = null,
|
||||
@@ -95,10 +93,12 @@ class OutputEncoderTest {
|
||||
@Test
|
||||
fun testMirrorTrackingReadsTheOppositeSideBone() {
|
||||
val leftRotation = Quaternion.rotationAroundXAxis(0.5f)
|
||||
val bones = registry.computedSkeletonOf(
|
||||
BodyPart.LEFT_UPPER_LEG to bone(BodyPart.LEFT_UPPER_LEG, leftRotation),
|
||||
BodyPart.RIGHT_UPPER_LEG to bone(BodyPart.RIGHT_UPPER_LEG),
|
||||
BodyPart.HIP to bone(BodyPart.HIP),
|
||||
val bones = BodyPartMap(
|
||||
mapOf(
|
||||
BodyPart.LEFT_UPPER_LEG to bone(BodyPart.LEFT_UPPER_LEG, leftRotation),
|
||||
BodyPart.RIGHT_UPPER_LEG to bone(BodyPart.RIGHT_UPPER_LEG),
|
||||
BodyPart.HIP to bone(BodyPart.HIP),
|
||||
),
|
||||
)
|
||||
val routed = setOf(BodyPart.HIP, BodyPart.LEFT_UPPER_LEG, BodyPart.RIGHT_UPPER_LEG)
|
||||
|
||||
@@ -119,9 +119,11 @@ class OutputEncoderTest {
|
||||
|
||||
@Test
|
||||
fun testVrmBindOffsetsReplaceComputedPositions() {
|
||||
val bones = registry.computedSkeletonOf(
|
||||
BodyPart.HIP to bone(BodyPart.HIP),
|
||||
BodyPart.LOWER_WAIST to bone(BodyPart.LOWER_WAIST),
|
||||
val bones = BodyPartMap(
|
||||
mapOf(
|
||||
BodyPart.HIP to bone(BodyPart.HIP),
|
||||
BodyPart.LOWER_WAIST to bone(BodyPart.LOWER_WAIST),
|
||||
),
|
||||
)
|
||||
val routed = setOf(BodyPart.HIP, BodyPart.LOWER_WAIST)
|
||||
val vrm = buildVrmGeometry(VrmReader(VRM_JSON))
|
||||
|
||||
@@ -14,7 +14,6 @@ import dev.slimevr.osc.OscMessage
|
||||
import dev.slimevr.quaternionApproxEqual
|
||||
import dev.slimevr.skeleton.Skeleton
|
||||
import dev.slimevr.skeleton.bodyPartMap
|
||||
import dev.slimevr.skeleton.boneId
|
||||
import dev.slimevr.vectorAssertEquals
|
||||
import io.github.axisangles.ktmath.Quaternion
|
||||
import io.github.axisangles.ktmath.Vector3
|
||||
@@ -80,7 +79,7 @@ class VMCInputBehaviourTest {
|
||||
harness.handle(boneBundle("Hips", Vector3(0f, 1f, 0f), Quaternion.rotationAroundYAxis(0.3f)))
|
||||
|
||||
val tracker = harness.trackers().single()
|
||||
assertEquals(BodyPart.HIP.boneId, tracker.context.state.value.boneId)
|
||||
assertEquals(BodyPart.HIP, tracker.context.state.value.bodyPart)
|
||||
assertEquals(DeviceOrigin.VMC, tracker.context.state.value.origin)
|
||||
vectorAssertEquals(Vector3(0f, 1f, 0f), assertNotNull(tracker.context.state.value.position))
|
||||
assertApprox(Quaternion.rotationAroundYAxis(0.3f), tracker.context.state.value.rawRotation)
|
||||
@@ -106,7 +105,7 @@ class VMCInputBehaviourTest {
|
||||
harness.handle(bundleOf(OscMessage("/VMC/Ext/Tra/Pos", transformArgs("serial-1", Vector3(0.5f, 0.5f, 0.5f), Quaternion.IDENTITY))))
|
||||
|
||||
val tracker = harness.trackers().single()
|
||||
assertNull(tracker.context.state.value.boneId)
|
||||
assertNull(tracker.context.state.value.bodyPart)
|
||||
assertEquals(DeviceOrigin.VMC, tracker.context.state.value.origin)
|
||||
vectorAssertEquals(Vector3(0.5f, 0.5f, 0.5f), assertNotNull(tracker.context.state.value.position))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user