mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-12-02 14:52:36 -08:00
Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0f649034a7 | ||
|
|
1f44744e2b | ||
|
|
cc803b59e3 | ||
|
|
70e41f113f | ||
|
|
fb3af2a9f1 | ||
|
|
476d81584d | ||
|
|
9937b42c46 | ||
|
|
a0f6bbfd92 | ||
|
|
06a54e106e | ||
|
|
39b57e770c | ||
|
|
6b28bb1a71 | ||
|
|
c151f1d2fa | ||
|
|
f31fd48f73 |
No files matched your search
+5
-4
@@ -7,8 +7,9 @@ This document describes essential knowledge required to contribute to the SlimeV
|
||||
### Prerequisites
|
||||
|
||||
- [Git](https://git-scm.com/downloads)
|
||||
- [Java v17+](https://adoptium.net/temurin/releases/)
|
||||
- [Node.js v16.9+](https://nodejs.org) (We recommend the use of `nvm` instead of installing Node.js directly)
|
||||
- [Java v25](https://adoptium.net/temurin/releases/)
|
||||
- [Node.js v24+](https://nodejs.org) (We recommend the use of `nvm` instead of installing Node.js directly)
|
||||
- [pnpm](https://pnpm.io/installation)
|
||||
|
||||
## Cloning the code
|
||||
First, clone the codebase using git in a terminal in the folder you want.
|
||||
@@ -36,13 +37,13 @@ be at `server/desktop/build/libs/slimevr.jar` (you can ignore `server.jar`).
|
||||
|
||||
### Electron (gui)
|
||||
|
||||
- Activate corepack (included with Node.js) via `corepack enable`
|
||||
- Activate corepack (included with Node.js) via `corepack enable`
|
||||
(might require launching Git Bash as administrator on Windows)
|
||||
- Make sure you're at the root of the repository.
|
||||
- Run `pnpm i` in your IDE's terminal to download and install dependencies.
|
||||
- To launch the GUI in dev mode, run `pnpm gui`.
|
||||
- If you get an "Electron uninstall" error, run `node .\gui\electron\node_modules\electron\install.js`.
|
||||
- Finally, to compile for production, run `pnpm package:build` under `gui/electron`.
|
||||
- Finally, to compile for production, run `pnpm package:build` under `gui/electron`.
|
||||
The result will be in `gui/dist/artifacts/`. Content will change depending on the platform.
|
||||
|
||||
## Code style
|
||||
|
||||
@@ -37,8 +37,9 @@ suspend fun createAndroidSolarXRWebsocketServer(appContext: AppContextProvider)
|
||||
appContext = appContext,
|
||||
scope = this,
|
||||
)
|
||||
val name = bridge.context.name
|
||||
|
||||
AppLogger.ipc.info("SolarXR[${bridge.id}] connected (websocket)")
|
||||
AppLogger.ipc.info("$name connected (websocket)")
|
||||
appContext.server.context.dispatch(VRServerActions.SolarXRConnected(bridge))
|
||||
|
||||
bridge.outbound.on<MessageBundle> { bundle ->
|
||||
@@ -54,7 +55,7 @@ suspend fun createAndroidSolarXRWebsocketServer(appContext: AppContextProvider)
|
||||
for (frame in incoming) {
|
||||
when (frame) {
|
||||
is Frame.Binary -> emit(frame.data)
|
||||
is Frame.Close -> AppLogger.ipc.info("SolarXR[${bridge.id}] connection closed")
|
||||
is Frame.Close -> AppLogger.ipc.info("$name connection closed")
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
@@ -63,7 +64,7 @@ suspend fun createAndroidSolarXRWebsocketServer(appContext: AppContextProvider)
|
||||
onSolarXRMessage(MessageBundle.decode(reader, reader.getInt(0)), bridge)
|
||||
}
|
||||
} finally {
|
||||
AppLogger.ipc.info("SolarXR[${bridge.id}] disconnected (websocket)")
|
||||
AppLogger.ipc.info("$name disconnected (websocket)")
|
||||
bridge.disconnect()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ data class SkeletonTogglesConfig(
|
||||
@Serializable
|
||||
data class SkeletonRatiosConfig(
|
||||
val smoothingStrength: Float = 0.15f,
|
||||
val predictionStrength: Float = 0.30f,
|
||||
val predictionStrength: Float = 0.25f,
|
||||
val spineCurvature: Float = 0.75f,
|
||||
val imputeSpineFromUpperToLower: Float = DEFAULT_SPINE_UPPER_LOWER,
|
||||
val interpolateUpperLegsTwistWithLowerLegs: Float = 0.85f,
|
||||
|
||||
@@ -47,7 +47,7 @@ import kotlin.time.Duration.Companion.seconds
|
||||
import kotlin.time.TimeMark
|
||||
|
||||
// Feet go slightly inwards on pose mounting
|
||||
private const val FEET_POSE_DEG_INWARDS = 15
|
||||
private const val FEET_POSE_DEG_INWARDS = 15 * FastMath.DEG_TO_RAD
|
||||
|
||||
data class ResetsState(
|
||||
val canDoYawReset: Boolean,
|
||||
@@ -237,9 +237,13 @@ class ResetsManager(
|
||||
|
||||
private fun getYawOffset(bodyPart: BodyPart?, armsResetMode: ArmsMountingResetMode) = when (bodyPart) {
|
||||
// Feet go back but a little inwards
|
||||
BodyPart.LEFT_FOOT -> FastMath.PI - FEET_POSE_DEG_INWARDS * FastMath.DEG_TO_RAD
|
||||
BodyPart.LEFT_FOOT -> FastMath.PI - FEET_POSE_DEG_INWARDS
|
||||
|
||||
BodyPart.RIGHT_FOOT -> FastMath.PI + FEET_POSE_DEG_INWARDS * FastMath.DEG_TO_RAD
|
||||
in ResetBodyParts.LEFT_TOES -> FastMath.PI - FEET_POSE_DEG_INWARDS
|
||||
|
||||
BodyPart.RIGHT_FOOT -> FastMath.PI + FEET_POSE_DEG_INWARDS
|
||||
|
||||
in ResetBodyParts.RIGHT_TOES -> FastMath.PI + FEET_POSE_DEG_INWARDS
|
||||
|
||||
// Going forward
|
||||
in ResetBodyParts.UPPER_LEGS -> 0f
|
||||
|
||||
@@ -75,6 +75,8 @@ class LocalizerResetBehaviour(val settings: Settings) : SkeletonBehaviour {
|
||||
*/
|
||||
class YouSpinMeRightRoundBehaviour(val inputHz: Int = 100, val speed: Float = 1f, val randomPacketLoss: Float = 0f, val constantPacketLoss: Float = 0f, val sendPosition: Boolean = false) : SkeletonBehaviour {
|
||||
override fun observe(receiver: Skeleton) {
|
||||
println("YouSpinMeRightRoundBehaviour sending fake bone data for simulation.")
|
||||
|
||||
receiver.context.scope.launch {
|
||||
val interval = (millisecondsInSecond / inputHz.toFloat()).toLong().milliseconds
|
||||
val startTime = timeSource.markNow()
|
||||
|
||||
@@ -36,7 +36,8 @@ private const val SMOOTHING_MS_MAX = 50.0
|
||||
|
||||
// Prediction
|
||||
private const val PREDICTION_MS_MAX = 30.0
|
||||
private const val PREVIOUS_PREDICTION_CARRYOVER = 0.2f
|
||||
private val PREDICTION_CARRYOVER_TIME = 25.milliseconds
|
||||
private const val MAX_PREDICTION_CARRYOVER_RATIO = 0.5
|
||||
|
||||
// Used to minimize latency even more for arm tracking where it is more noticeable
|
||||
private val PART_MULTIPLIER = BodyPartMap(
|
||||
@@ -100,7 +101,8 @@ private fun computePredictedRotation(
|
||||
if (previousRotation == null) return targetRotation
|
||||
|
||||
// Use some of the previous prediction
|
||||
val previousPredictionDelta = previousPredictedRotation?.localAbout(previousRotation)?.pow(PREVIOUS_PREDICTION_CARRYOVER)
|
||||
val carryoverRatio = (PREDICTION_CARRYOVER_TIME / poseTimeDelta).coerceAtMost(MAX_PREDICTION_CARRYOVER_RATIO).toFloat()
|
||||
val previousPredictionDelta = previousPredictedRotation?.localAbout(previousRotation)?.pow(carryoverRatio)
|
||||
?: Quaternion.IDENTITY
|
||||
|
||||
val currentDelta = if (poseTimeDelta > Duration.ZERO) {
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package dev.slimevr.skeleton.inputprocessors
|
||||
|
||||
import dev.slimevr.skeleton.BodyPartMap
|
||||
import dev.slimevr.skeleton.BoneInput
|
||||
import dev.slimevr.skeleton.InputSkeleton
|
||||
import dev.slimevr.skeleton.SkeletonInputProcessor
|
||||
import dev.slimevr.skeleton.bodyPartMap
|
||||
import kotlin.random.Random
|
||||
import kotlin.time.ComparableTimeMark
|
||||
|
||||
/**
|
||||
* Used for simulating packet drop, leave commented for production.
|
||||
*/
|
||||
class PacketDropSimulatorInputProcessor(val randomPacketDrop: Float) : SkeletonInputProcessor {
|
||||
init {
|
||||
println("PacketDropSimulatorInputProcessor simulating ${randomPacketDrop * 100}% packet drop.")
|
||||
}
|
||||
|
||||
val lastBone: BodyPartMap<BoneInput> = bodyPartMap()
|
||||
val lastPoseTime: BodyPartMap<ComparableTimeMark> = bodyPartMap()
|
||||
override fun process(mutableInputSkeleton: InputSkeleton, skeletonHeight: Float) {
|
||||
mutableInputSkeleton.forEach { (part, input) ->
|
||||
val isNewData = lastPoseTime[part] != mutableInputSkeleton[part]?.poseTime
|
||||
lastPoseTime[part] = mutableInputSkeleton[part]?.poseTime
|
||||
if (isNewData) {
|
||||
val dropPacket = Random.nextFloat() < randomPacketDrop
|
||||
if (!dropPacket) {
|
||||
lastBone[part] = input
|
||||
} else if (lastBone[part] != null) {
|
||||
mutableInputSkeleton[part] = lastBone[part]
|
||||
}
|
||||
} else if (lastBone[part] != null) {
|
||||
mutableInputSkeleton[part] = lastBone[part]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import dev.slimevr.skeleton.inputprocessors.FilteringInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.FingersInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.HeadPositionFallbackInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.NeckInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.PacketDropSimulatorInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.SpineInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.ToesInputProcessor
|
||||
import dev.slimevr.skeleton.targetprocessors.FloorClipTargetProcessor
|
||||
@@ -262,12 +263,13 @@ class Skeleton(
|
||||
ProportionsBehaviour(ctx.config.userConfig),
|
||||
HeightLogBehaviour(),
|
||||
LocalizerResetBehaviour(settings),
|
||||
// YouSpinMeRightRoundBehaviour(inputHz = 100, speed = 1f, randomPacketLoss = 0f, constantPacketLoss = 0f, sendPosition = true),
|
||||
// YouSpinMeRightRoundBehaviour(inputHz = 100, speed = 1f, randomPacketLoss = 0.9f, constantPacketLoss = 0f, sendPosition = false),
|
||||
ComputedSkeletonBehaviour(
|
||||
hz = hz,
|
||||
waiter = waiter,
|
||||
// Run before FK on the inputs
|
||||
inputProcessors = listOf(
|
||||
// PacketDropSimulatorInputProcessor(0.85f),
|
||||
FilteringInputProcessor(settings),
|
||||
HeadPositionFallbackInputProcessor(),
|
||||
FallbackInputProcessor(),
|
||||
|
||||
+6
-3
@@ -26,8 +26,13 @@ val POSITIONAL_IK_TARGETS = arrayOf(
|
||||
BodyPart.RIGHT_FOOT to BodyPart.RIGHT_LOWER_LEG,
|
||||
)
|
||||
|
||||
val requiredInactive = BodyPartMap(
|
||||
// TODO Use active rotations as IK constraints instead and fill in the blanks
|
||||
private val requiredInactive = BodyPartMap(
|
||||
mapOf(
|
||||
BodyPart.LEFT_LOWER_LEG to arrayOf(BodyPart.LEFT_UPPER_LEG),
|
||||
BodyPart.RIGHT_LOWER_LEG to arrayOf(BodyPart.RIGHT_UPPER_LEG),
|
||||
BodyPart.LEFT_FOOT to arrayOf(BodyPart.LEFT_LOWER_LEG, BodyPart.LEFT_UPPER_LEG),
|
||||
BodyPart.RIGHT_FOOT to arrayOf(BodyPart.RIGHT_LOWER_LEG, BodyPart.RIGHT_UPPER_LEG),
|
||||
BodyPart.LEFT_HAND to arrayOf(BodyPart.LEFT_SHOULDER, BodyPart.LEFT_UPPER_ARM, BodyPart.LEFT_LOWER_ARM),
|
||||
BodyPart.RIGHT_HAND to arrayOf(BodyPart.RIGHT_SHOULDER, BodyPart.RIGHT_UPPER_ARM, BodyPart.RIGHT_LOWER_ARM),
|
||||
),
|
||||
@@ -41,8 +46,6 @@ class PositionalTargetProcessor(
|
||||
override fun process(mutableIkTargets: IKTargets, inputSkeleton: InputSkeleton, fk: ComputedSkeleton, floorLevel: Float) {
|
||||
if (!settings.context.state.value.data.skeletonConfig.toggles.useTrackerPositions) return
|
||||
for ((bodyPart, target) in bodyParts) {
|
||||
// TODO Use active rotations as IK constraints instead and fill in the blanks
|
||||
// Disable if you have arm trackers
|
||||
if (requiredInactive[bodyPart]?.any { inputSkeleton[it]?.isRotationActive == true } == true) continue
|
||||
|
||||
mutableIkTargets[target] = inputSkeleton[bodyPart]?.position ?: continue
|
||||
|
||||
+5
-1
@@ -27,6 +27,7 @@ const val OFFSET_LIMIT_MAX = 0.20f
|
||||
const val COM_DISTANCE_MULTIPLIER = 1.5f
|
||||
const val LIFT_MIN = -0.85f
|
||||
const val LIFT_MAX = 0.4f
|
||||
const val ANKLE_MULTIPLIER = 1.25f
|
||||
|
||||
// Parameters to decide if a foot should be locked
|
||||
// Higher makes it harder to unlock after being locked
|
||||
@@ -226,6 +227,7 @@ class SkatingCorrectionTargetProcessor(val settings: Settings, val skeleton: Ske
|
||||
|
||||
for ((bodyPart, ikTargetBodyPart, liftBodyPart) in skatingBodyParts) {
|
||||
val bone = fk[bodyPart] ?: continue
|
||||
val inputBone = inputSkeleton[bodyPart] ?: continue
|
||||
val ikBone = fk[ikTargetBodyPart] ?: continue
|
||||
val liftBone = fk[liftBodyPart] ?: continue
|
||||
val curPosition = mutableIkTargets[ikTargetBodyPart] ?: ikBone.tailPosition
|
||||
@@ -235,8 +237,10 @@ class SkatingCorrectionTargetProcessor(val settings: Settings, val skeleton: Ske
|
||||
val comMultiplier = computeComMultiplier(comDistances[bodyPart] ?: continue, comDistancesAverage)
|
||||
// liftMultiplier decreases the threshold when the upper leg is lifted. Useful when sitting/lying down
|
||||
val liftMultiplier = computeLiftMultiplier(liftBone.localTailPosition)
|
||||
// ankleMultiplier increases the threshold if the foot doesn't have its own accel data
|
||||
val ankleMultiplier = if (inputBone.isAccelerationActive) 1f else ANKLE_MULTIPLIER
|
||||
// Apply multipliers to the acceleration threshold
|
||||
val scaledAccelerationThreshold = accelerationThreshold * comMultiplier * liftMultiplier
|
||||
val scaledAccelerationThreshold = accelerationThreshold * comMultiplier * liftMultiplier * ankleMultiplier
|
||||
|
||||
// Compute if the body part should be locked
|
||||
val floorLocked = floorLocked(lastState.locked, curPosition, floorLevel)
|
||||
|
||||
@@ -207,10 +207,7 @@ class DataFeedInitBehaviour(
|
||||
|
||||
receiver.datafeedTimers.forEach { it.cancelAndJoin() }
|
||||
|
||||
AppLogger.solarxr.info(
|
||||
"SolarXR[${receiver.id}] data feed started: " +
|
||||
dataFeeds.joinToString { "every ${it.minimumTimeSinceLast}ms" },
|
||||
)
|
||||
AppLogger.solarxr.info("Started ${dataFeeds.size} data feeds: " + dataFeeds.joinToString { "${it.minimumTimeSinceLast}ms" })
|
||||
|
||||
val timers = dataFeeds.mapIndexed { index, config ->
|
||||
receiver.context.scope.launch {
|
||||
|
||||
@@ -22,6 +22,10 @@ import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import solarxr_protocol.datatypes.MagnetometerStatus
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
// When a tracker comes back from sleep, prevents a disproportionate correction
|
||||
private val MAX_DELTA_TIME = 0.5.seconds
|
||||
|
||||
class TrackerStayAlignedBehaviour(
|
||||
private val settings: Settings,
|
||||
@@ -72,20 +76,17 @@ class TrackerStayAlignedBehaviour(
|
||||
.flatMapLatest { (enabled, imuType, magStatus) ->
|
||||
if (magStatus == MagnetometerStatus.ENABLED || imuType == null || !enabled) return@flatMapLatest emptyFlow()
|
||||
|
||||
// Ignore every other emission for performance (50FPS instead of 100FPS when at 100TPS)
|
||||
var index = 0
|
||||
var lastRotationTime = timeSource.markNow()
|
||||
receiver.context.state
|
||||
.distinctUntilChangedBy { it.rawRotation }
|
||||
.filter { index++ % 2 == 0 }
|
||||
.onEach { state ->
|
||||
val yawCorrectionPerSec = IMU_TO_YAW_CORRECTION.getOrDefault(imuType, YAW_CORRECTION_DEFAULT)
|
||||
if (yawCorrectionPerSec == Angle.ZERO) return@onEach
|
||||
|
||||
val lastFrameTimeSeconds = lastRotationTime.elapsedNow().inFloatingSeconds
|
||||
val deltaTime = lastRotationTime.elapsedNow().coerceAtMost(MAX_DELTA_TIME).inFloatingSeconds
|
||||
lastRotationTime = timeSource.markNow()
|
||||
|
||||
val applyYawCorrection = yawCorrectionPerSec * lastFrameTimeSeconds
|
||||
val applyYawCorrection = yawCorrectionPerSec * deltaTime
|
||||
|
||||
val yawCorrectionResult = TrackerYawCorrection.computeYawCorrection(
|
||||
state,
|
||||
|
||||
@@ -183,8 +183,6 @@ class SteamVRHandsCheckBehaviour(
|
||||
routes: Routes,
|
||||
driverConnected: Boolean,
|
||||
): TrackingChecklistStep {
|
||||
// The skeleton computes a hand bone from the arm chain, so routing one sends a hand
|
||||
// tracker to SteamVR whether or not the user wears anything on that hand.
|
||||
val handsSentToDriver = HAND_BONES.any { hand -> routes[hand]?.contains(RoutingOutput.DRIVER) == true }
|
||||
val handTrackers = trackers.filter { tracker -> tracker.bodyPart in HAND_BONES }
|
||||
// Controllers reach us back through the driver, anything else on a hand is a
|
||||
|
||||
@@ -18,6 +18,7 @@ import dev.slimevr.solarxr.onSolarXRMessage
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.engine.cio.CIO
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.cancelChildren
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
@@ -31,6 +32,7 @@ import okio.Buffer
|
||||
import solarxr_protocol.MessageBundle
|
||||
import solarxr_protocol.rpc.EnableSteamVRDriverRequest
|
||||
import solarxr_protocol.rpc.OpenKeybindSettingsRequest
|
||||
import java.io.IOException
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
class EnableSteamVRDriverBehaviour : SolarXRBridgeBehaviour {
|
||||
@@ -89,8 +91,9 @@ suspend fun handleSolarXRBridge(
|
||||
}
|
||||
},
|
||||
)
|
||||
val name = bridge.context.name
|
||||
|
||||
AppLogger.solarxr.info("SolarXR[${bridge.id}] connected ($transport)")
|
||||
AppLogger.solarxr.info("$name connected ($transport)")
|
||||
appContext.server.context.dispatch(VRServerActions.SolarXRConnected(bridge))
|
||||
|
||||
// One builder and one send buffer for the life of the connection. clear() keeps the buffer it has
|
||||
@@ -103,7 +106,12 @@ suspend fun handleSolarXRBridge(
|
||||
fbb.clear()
|
||||
fbb.finish(bundle.encode(JvmFlatBufferWriter(fbb)))
|
||||
sendBuffer.write(fbb.dataBuffer())
|
||||
send(sendBuffer)
|
||||
try {
|
||||
send(sendBuffer)
|
||||
} catch (e: IOException) {
|
||||
AppLogger.solarxr.warn("Exception when sending bundle to $name: ${e.message}")
|
||||
cancel()
|
||||
}
|
||||
}.launchIn(this)
|
||||
|
||||
bridge.startObserving()
|
||||
@@ -121,7 +129,7 @@ suspend fun handleSolarXRBridge(
|
||||
onSolarXRMessage(MessageBundle.decode(reader, reader.getInt(0)), bridge)
|
||||
}
|
||||
} finally {
|
||||
AppLogger.solarxr.info("SolarXR[${bridge.id}] disconnected ($transport)")
|
||||
AppLogger.solarxr.info("$name disconnected ($transport)")
|
||||
bridge.disconnect()
|
||||
coroutineContext.cancelChildren()
|
||||
}
|
||||
|
||||
@@ -57,8 +57,8 @@ private fun readFramedMessages(channel: SocketChannel) = flow {
|
||||
emit(frame)
|
||||
}
|
||||
} catch (e: SocketException) {
|
||||
AppLogger.ipc.warn("Exception on socket: ${e.message}")
|
||||
} catch (e: ClosedByInterruptException) {
|
||||
AppLogger.ipc.warn("Exception reading from socket: ${e.message}")
|
||||
} catch (_: ClosedByInterruptException) {
|
||||
AppLogger.ipc.info("Socket read interrupted, dropping connection")
|
||||
}
|
||||
}
|
||||
@@ -120,7 +120,7 @@ private suspend fun acceptUnixClients(
|
||||
while (isActive) {
|
||||
val client = try {
|
||||
runInterruptible { server.accept() }
|
||||
} catch (e: ClosedByInterruptException) {
|
||||
} catch (_: ClosedByInterruptException) {
|
||||
break
|
||||
}
|
||||
AppLogger.ipc.info("$name client connected")
|
||||
@@ -135,7 +135,7 @@ private suspend fun acceptUnixClients(
|
||||
AppLogger.ipc.info("$name client disconnected")
|
||||
try {
|
||||
client.close()
|
||||
} catch (ignored: IOException) {
|
||||
} catch (_: IOException) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user