mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-23 18:41:24 -08:00
Compare commits
14
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70618ab1ed | ||
|
|
9057a22a8e | ||
|
|
5cf5e95d91 | ||
|
|
2df8865325 | ||
|
|
d9535f61f3 | ||
|
|
e3595380a7 | ||
|
|
abb8c9b66c | ||
|
|
9614abea08 | ||
|
|
2c125b2540 | ||
|
|
6974122c99 | ||
|
|
a7ffbd9ea8 | ||
|
|
d04c7796bf | ||
|
|
1829e4e234 | ||
|
|
1caa2a5049 |
No files matched your search
+5
-1
@@ -44,5 +44,9 @@ build/
|
||||
# Ignore Android local properties
|
||||
local.properties
|
||||
|
||||
# Ignore temporary config
|
||||
# Ignore vrconfig
|
||||
vrconfig.yml
|
||||
vrconfig.yml.tmp
|
||||
vrconfig.yml.bak
|
||||
vrconfig.yml.*.bak.tmp
|
||||
vrconfig.yml.*.bak
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src-tauri/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -6,6 +6,9 @@ import { Typography } from '@/components/commons/Typography';
|
||||
import { useLocalization } from '@fluent/react';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { flatTrackersAtom } from '@/store/app-store';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { ChangeSettingsRequestT, ModelSettingsT, ModelTogglesT, RpcMessage, SettingsRequestT, SettingsResponseT } from 'solarxr-protocol';
|
||||
import { useWebsocketAPI } from '@/hooks/websocket-api';
|
||||
|
||||
export function PutTrackersOnStep({
|
||||
nextStep,
|
||||
@@ -18,6 +21,7 @@ export function PutTrackersOnStep({
|
||||
const trackers = useAtomValue(flatTrackersAtom);
|
||||
const { l10n } = useLocalization();
|
||||
|
||||
|
||||
return (
|
||||
<div className="flex mobile:flex-col items-center w-full">
|
||||
<div className="flex flex-col flex-grow gap-2">
|
||||
|
||||
@@ -5,7 +5,6 @@ build
|
||||
*/bin/
|
||||
|
||||
MagnetoLib.dll
|
||||
vrconfig.yml
|
||||
|
||||
# BVH
|
||||
BVH Recordings
|
||||
|
||||
@@ -64,10 +64,7 @@ dependencies {
|
||||
// and not exposed to consumers on their own compile classpath.
|
||||
implementation("com.google.flatbuffers:flatbuffers-java:22.10.26")
|
||||
implementation("commons-cli:commons-cli:1.8.0")
|
||||
implementation("com.fasterxml.jackson.core:jackson-databind:2.15.1")
|
||||
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.15.1")
|
||||
|
||||
implementation("com.github.jonpeterson:jackson-module-model-versioning:1.2.2")
|
||||
implementation("org.apache.commons:commons-math3:3.6.1")
|
||||
implementation("org.apache.commons:commons-lang3:3.15.0")
|
||||
implementation("org.apache.commons:commons-collections4:4.4")
|
||||
@@ -75,7 +72,11 @@ dependencies {
|
||||
implementation("com.illposed.osc:javaosc-core:0.8")
|
||||
implementation("org.java-websocket:Java-WebSocket:1.+")
|
||||
implementation("com.melloware:jintellitype:1.+")
|
||||
|
||||
implementation("com.squareup.okio:okio:3.10.2")
|
||||
implementation("net.mamoe.yamlkt:yamlkt:0.13.0")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.7.3")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1")
|
||||
implementation("com.mayakapps.kache:kache:2.1.0")
|
||||
|
||||
|
||||
@@ -9,8 +9,6 @@ import io.eiren.util.ann.AWTThread
|
||||
import io.eiren.util.logging.LogManager
|
||||
|
||||
class Keybinding @AWTThread constructor(val server: VRServer) : HotkeyListener {
|
||||
val config: KeybindingsConfig = server.configManager.vrConfig.keybindings
|
||||
|
||||
init {
|
||||
if (currentPlatform != OperatingSystem.WINDOWS) {
|
||||
LogManager
|
||||
@@ -18,6 +16,7 @@ class Keybinding @AWTThread constructor(val server: VRServer) : HotkeyListener {
|
||||
"[Keybinding] Currently only supported on Windows. Keybindings will be disabled.",
|
||||
)
|
||||
} else {
|
||||
val config = server.configManager.settings.get().keybindings
|
||||
try {
|
||||
if (JIntellitype.getInstance() != null) {
|
||||
JIntellitype.getInstance().addHotKeyListener(this)
|
||||
@@ -51,8 +50,8 @@ class Keybinding @AWTThread constructor(val server: VRServer) : HotkeyListener {
|
||||
}
|
||||
}
|
||||
|
||||
@AWTThread
|
||||
override fun onHotKey(identifier: Int) {
|
||||
val config = server.configManager.settings.get().keybindings
|
||||
when (identifier) {
|
||||
FULL_RESET -> server.scheduleResetTrackersFull(RESET_SOURCE_NAME, config.fullResetDelay)
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ class VRServer @JvmOverloads constructor(
|
||||
val computedTrackers = humanPoseManager.computedTrackers
|
||||
|
||||
// Start server for SlimeVR trackers
|
||||
val trackerPort = configManager.vrConfig.server.trackerPort
|
||||
val trackerPort = configManager.settings.get().server.trackerPort
|
||||
LogManager.info("Starting the tracker server on port $trackerPort...")
|
||||
trackersServer = TrackersUDPServer(
|
||||
trackerPort,
|
||||
@@ -160,20 +160,18 @@ class VRServer @JvmOverloads constructor(
|
||||
// Initialize OSC handlers
|
||||
vrcOSCHandler = VRCOSCHandler(
|
||||
this,
|
||||
configManager.vrConfig.vrcOSC,
|
||||
computedTrackers,
|
||||
)
|
||||
vMCHandler = VMCHandler(
|
||||
this,
|
||||
humanPoseManager,
|
||||
configManager.vrConfig.vmc,
|
||||
)
|
||||
|
||||
// Initialize OSC router
|
||||
val oscHandlers = FastList<OSCHandler>()
|
||||
oscHandlers.add(vrcOSCHandler)
|
||||
oscHandlers.add(vMCHandler)
|
||||
oSCRouter = OSCRouter(configManager.vrConfig.oscRouter, oscHandlers)
|
||||
oSCRouter = OSCRouter(configManager.settings, oscHandlers)
|
||||
bvhRecorder = BVHRecorder(this)
|
||||
for (tracker in computedTrackers) {
|
||||
registerTracker(tracker)
|
||||
@@ -219,13 +217,12 @@ class VRServer @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
@ThreadSafe
|
||||
fun trackerUpdated(tracker: Tracker?) {
|
||||
fun trackerUpdated(tracker: Tracker) {
|
||||
queueTask {
|
||||
humanPoseManager.trackerUpdated(tracker)
|
||||
updateSkeletonModel()
|
||||
refreshTrackersDriftCompensationEnabled()
|
||||
configManager.vrConfig.writeTrackerConfig(tracker)
|
||||
configManager.saveConfig()
|
||||
tracker.readConfig(configManager)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,8 +283,8 @@ class VRServer @JvmOverloads constructor(
|
||||
|
||||
@ThreadSecure
|
||||
fun registerTracker(tracker: Tracker) {
|
||||
configManager.vrConfig.readTrackerConfig(tracker)
|
||||
queueTask {
|
||||
tracker.readConfig(configManager)
|
||||
trackers.add(tracker)
|
||||
trackerAdded(tracker)
|
||||
for (tc in newTrackersConsumers) {
|
||||
|
||||
@@ -60,9 +60,6 @@ class AutoBone(private val server: VRServer) {
|
||||
var positionOffsetError = PositionOffsetError()
|
||||
// #endregion
|
||||
|
||||
val globalConfig: AutoBoneConfig = server.configManager.vrConfig.autoBone
|
||||
val globalSkeletonConfig: SkeletonConfig = server.configManager.vrConfig.skeleton
|
||||
|
||||
init {
|
||||
loadConfigValues()
|
||||
}
|
||||
@@ -112,7 +109,7 @@ class AutoBone(private val server: VRServer) {
|
||||
|
||||
fun calcTargetHmdHeight(
|
||||
frames: PoseFrames,
|
||||
config: AutoBoneConfig = globalConfig,
|
||||
config: AutoBoneConfig,
|
||||
): Float {
|
||||
val targetHeight: Float
|
||||
// Get the current skeleton from the server
|
||||
@@ -214,13 +211,16 @@ class AutoBone(private val server: VRServer) {
|
||||
@Throws(AutoBoneException::class)
|
||||
fun processFrames(
|
||||
frames: PoseFrames,
|
||||
config: AutoBoneConfig = globalConfig,
|
||||
skeletonConfig: SkeletonConfig = globalSkeletonConfig,
|
||||
// config: AutoBoneConfig = globalConfig,
|
||||
// skeletonConfig: SkeletonConfig = globalSkeletonConfig,
|
||||
epochCallback: Consumer<Epoch>? = null,
|
||||
): AutoBoneResults {
|
||||
check(frames.frameHolders.isNotEmpty()) { "Recording has no trackers." }
|
||||
check(frames.maxFrameCount > 0) { "Recording has no frames." }
|
||||
|
||||
val config = server.configManager.settings.get().autoBone
|
||||
val skeletonConfig = server.configManager.user.get().skeleton
|
||||
|
||||
// Load current values for adjustable configs
|
||||
loadConfigValues()
|
||||
|
||||
|
||||
@@ -100,9 +100,10 @@ class AutoBoneHandler(private val server: VRServer) {
|
||||
if (poseRecorder.isReadyToRecord) {
|
||||
announceProcessStatus(AutoBoneProcessType.RECORD, "Recording...")
|
||||
|
||||
val config = server.configManager.settings.get().autoBone
|
||||
// ex. 1000 samples at 20 ms per sample is 20 seconds
|
||||
val sampleCount = autoBone.globalConfig.sampleCount
|
||||
val sampleRate = autoBone.globalConfig.sampleRateMs / 1000f
|
||||
val sampleCount = config.sampleCount
|
||||
val sampleRate = config.sampleRateMs / 1000f
|
||||
// Calculate total time in seconds
|
||||
val totalTime: Float = sampleCount * sampleRate
|
||||
|
||||
@@ -124,7 +125,7 @@ class AutoBoneHandler(private val server: VRServer) {
|
||||
// Save a recurring recording for users to send as debug info
|
||||
announceProcessStatus(AutoBoneProcessType.RECORD, "Saving recording...")
|
||||
autoBone.saveRecording(frames, "LastABRecording.pfs")
|
||||
if (autoBone.globalConfig.saveRecordings) {
|
||||
if (config.saveRecordings) {
|
||||
announceProcessStatus(
|
||||
AutoBoneProcessType.RECORD,
|
||||
"Saving recording (from config option)...",
|
||||
|
||||
@@ -1,28 +1,31 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
class AutoBoneConfig {
|
||||
var cursorIncrement = 2
|
||||
var minDataDistance = 1
|
||||
var maxDataDistance = 1
|
||||
var numEpochs = 50
|
||||
var printEveryNumEpochs = 25
|
||||
var initialAdjustRate = 10.0f
|
||||
var adjustRateDecay = 1.0f
|
||||
var slideErrorFactor = 1.0f
|
||||
var offsetSlideErrorFactor = 0.0f
|
||||
var footHeightOffsetErrorFactor = 0.0f
|
||||
var bodyProportionErrorFactor = 0.05f
|
||||
var heightErrorFactor = 0.0f
|
||||
var positionErrorFactor = 0.0f
|
||||
var positionOffsetErrorFactor = 0.0f
|
||||
var calcInitError = false
|
||||
var randomizeFrameOrder = true
|
||||
var scaleEachStep = true
|
||||
var sampleCount = 1500
|
||||
var sampleRateMs = 20L
|
||||
var saveRecordings = false
|
||||
var useSkeletonHeight = false
|
||||
var randSeed = 4L
|
||||
var useFrameFiltering = false
|
||||
var maxFinalError = 0.03f
|
||||
}
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class AutoBoneConfig(
|
||||
val cursorIncrement: Int = 2,
|
||||
val minDataDistance: Int = 1,
|
||||
val maxDataDistance: Int = 1,
|
||||
val numEpochs: Int = 50,
|
||||
val printEveryNumEpochs: Int = 25,
|
||||
val initialAdjustRate: Float = 10.0f,
|
||||
val adjustRateDecay: Float = 1.0f,
|
||||
val slideErrorFactor: Float = 1.0f,
|
||||
val offsetSlideErrorFactor: Float = 0.0f,
|
||||
val footHeightOffsetErrorFactor: Float = 0.0f,
|
||||
val bodyProportionErrorFactor: Float = 0.05f,
|
||||
val heightErrorFactor: Float = 0.0f,
|
||||
val positionErrorFactor: Float = 0.0f,
|
||||
val positionOffsetErrorFactor: Float = 0.0f,
|
||||
val calcInitError: Boolean = false,
|
||||
val randomizeFrameOrder: Boolean = true,
|
||||
val scaleEachStep: Boolean = true,
|
||||
val sampleCount: Int = 1500,
|
||||
val sampleRateMs: Long = 20L,
|
||||
val saveRecordings: Boolean = false,
|
||||
val useSkeletonHeight: Boolean = false,
|
||||
val randSeed: Long = 4L,
|
||||
val useFrameFiltering: Boolean = false,
|
||||
val maxFinalError: Float = 0.03f,
|
||||
)
|
||||
@@ -1,33 +0,0 @@
|
||||
package dev.slimevr.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.StdKeySerializers;
|
||||
import dev.slimevr.config.serializers.BooleanMapDeserializer;
|
||||
import dev.slimevr.tracking.trackers.TrackerRole;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class BridgeConfig {
|
||||
|
||||
@JsonDeserialize(using = BooleanMapDeserializer.class)
|
||||
@JsonSerialize(keyUsing = StdKeySerializers.StringKeySerializer.class)
|
||||
public Map<String, Boolean> trackers = new HashMap<>();
|
||||
public boolean automaticSharedTrackersToggling = true;
|
||||
|
||||
public BridgeConfig() {
|
||||
}
|
||||
|
||||
public boolean getBridgeTrackerRole(TrackerRole role, boolean def) {
|
||||
return trackers.getOrDefault(role.name().toLowerCase(), def);
|
||||
}
|
||||
|
||||
public void setBridgeTrackerRole(TrackerRole role, boolean val) {
|
||||
this.trackers.put(role.name().toLowerCase(), val);
|
||||
}
|
||||
|
||||
public Map<String, Boolean> getTrackers() {
|
||||
return trackers;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
import dev.slimevr.tracking.trackers.TrackerRole
|
||||
import kotlinx.serialization.Serializable
|
||||
import java.util.*
|
||||
|
||||
@Serializable
|
||||
class BridgeConfig {
|
||||
var trackers: MutableMap<String, Boolean> = HashMap<String, Boolean>()
|
||||
var automaticSharedTrackersToggling: Boolean = true
|
||||
|
||||
fun getBridgeTrackerRole(role: TrackerRole, def: Boolean): Boolean = trackers.getOrDefault(role.name.lowercase(Locale.getDefault()), def)!!
|
||||
|
||||
fun setBridgeTrackerRole(role: TrackerRole, `val`: Boolean) {
|
||||
this.trackers[role.name.lowercase(Locale.getDefault())] = `val`
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
import io.eiren.util.logging.LogManager
|
||||
import kotlinx.serialization.KSerializer
|
||||
import net.mamoe.yamlkt.Yaml
|
||||
import net.mamoe.yamlkt.YamlMap
|
||||
import okio.FileSystem
|
||||
import okio.Path.Companion.toOkioPath
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import java.nio.file.StandardCopyOption
|
||||
|
||||
inline fun <reified T : Any> ConfigFileHandler<T>.modify(crossinline transform: T.() -> T): T = update { it.transform() }
|
||||
open class ConfigFileHandler<T : Any>(
|
||||
private val serializer: KSerializer<T>,
|
||||
val initDefault: () -> T,
|
||||
private val path: String,
|
||||
private val currentVersion: Int,
|
||||
private val migrateYamlConfig: ((YamlMap, Int) -> YamlMap)?,
|
||||
) {
|
||||
|
||||
@Volatile
|
||||
private lateinit var value: T
|
||||
|
||||
private val cfgFile = Paths.get(path)
|
||||
private val tmpCfgFile = Paths.get("$path.tmp")
|
||||
|
||||
@Synchronized
|
||||
fun get(): T = value
|
||||
|
||||
fun set(newValue: T) {
|
||||
value = newValue
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun update(transform: (T) -> T): T {
|
||||
value = transform(value)
|
||||
return value
|
||||
}
|
||||
|
||||
fun load(): T {
|
||||
if (!cfgFile.toFile().exists()) {
|
||||
value = initDefault()
|
||||
return value
|
||||
}
|
||||
|
||||
try {
|
||||
if (migrateYamlConfig != null) {
|
||||
handleMigrations()
|
||||
}
|
||||
value = decode(readAndPrepareYaml())
|
||||
} catch (e: Exception) {
|
||||
LogManager.severe("Failed to load config", e)
|
||||
backup()
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun save() {
|
||||
val snapshot = value
|
||||
|
||||
runCatching {
|
||||
writeToTmp(encode(snapshot))
|
||||
atomicMove(tmpCfgFile, cfgFile)
|
||||
}.onFailure {
|
||||
LogManager.severe("Failed to save config", it)
|
||||
}
|
||||
}
|
||||
|
||||
fun reset(): T {
|
||||
value = initDefault()
|
||||
save()
|
||||
return value
|
||||
}
|
||||
|
||||
private fun handleMigrations() {
|
||||
val root = decodeYamlRoot(readAndPrepareYaml())
|
||||
val version = root["version"]
|
||||
?.toString()
|
||||
?.toIntOrNull()
|
||||
?: error("Missing version")
|
||||
|
||||
if (version >= currentVersion) return
|
||||
|
||||
backup(".v$version")
|
||||
|
||||
val migrated = migrateYamlConfig(root, version)
|
||||
writeToTmp(Yaml.encodeToString(migrated))
|
||||
atomicMove(tmpCfgFile, cfgFile)
|
||||
}
|
||||
|
||||
private fun readAndPrepareYaml(): String = FileSystem.SYSTEM.read(cfgFile.toOkioPath()) {
|
||||
readUtf8().trim()
|
||||
}
|
||||
|
||||
private fun encode(data: T): String = Yaml.encodeToString(serializer, data)
|
||||
|
||||
private fun decode(yaml: String): T = Yaml.decodeFromString(serializer, yaml)
|
||||
|
||||
private fun decodeYamlRoot(yaml: String): YamlMap = Yaml.decodeYamlFromString(yaml) as YamlMap
|
||||
|
||||
private fun writeToTmp(text: String) {
|
||||
cfgFile.parent?.toFile()?.mkdirs()
|
||||
tmpCfgFile.toFile().writeText(text)
|
||||
}
|
||||
|
||||
private fun backup(suffix: String = "") {
|
||||
val tmp = Paths.get("$path$suffix.bak.tmp")
|
||||
val bak = Paths.get("$path$suffix.bak")
|
||||
|
||||
runCatching {
|
||||
Files.copy(cfgFile, tmp, StandardCopyOption.REPLACE_EXISTING)
|
||||
atomicMove(tmp, bak)
|
||||
}.onFailure {
|
||||
LogManager.severe("Backup failed", it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun atomicMove(from: Path, to: Path) {
|
||||
try {
|
||||
Files.move(from, to, StandardCopyOption.ATOMIC_MOVE)
|
||||
} catch (_: Exception) {
|
||||
Files.move(from, to, StandardCopyOption.REPLACE_EXISTING)
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun updateAndSave(transform: (T) -> T): T {
|
||||
val result = update(transform)
|
||||
save()
|
||||
return result
|
||||
}
|
||||
}
|
||||
@@ -1,176 +0,0 @@
|
||||
package dev.slimevr.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
|
||||
import com.github.jonpeterson.jackson.module.versioning.VersioningModule;
|
||||
import dev.slimevr.config.serializers.QuaternionDeserializer;
|
||||
import dev.slimevr.config.serializers.QuaternionSerializer;
|
||||
import io.eiren.util.ann.ThreadSafe;
|
||||
import io.eiren.util.logging.LogManager;
|
||||
import io.github.axisangles.ktmath.ObjectQuaternion;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
import java.util.Comparator;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
||||
public class ConfigManager {
|
||||
|
||||
private final String configPath;
|
||||
|
||||
private final ObjectMapper om;
|
||||
|
||||
private VRConfig vrConfig;
|
||||
|
||||
|
||||
public ConfigManager(String configPath) {
|
||||
this.configPath = configPath;
|
||||
om = new ObjectMapper(new YAMLFactory().disable(YAMLGenerator.Feature.SPLIT_LINES));
|
||||
om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
om.registerModule(new VersioningModule());
|
||||
SimpleModule quaternionModule = new SimpleModule();
|
||||
quaternionModule.addSerializer(ObjectQuaternion.class, new QuaternionSerializer());
|
||||
quaternionModule.addDeserializer(ObjectQuaternion.class, new QuaternionDeserializer());
|
||||
om.registerModule(quaternionModule);
|
||||
}
|
||||
|
||||
public void loadConfig() {
|
||||
try {
|
||||
this.vrConfig = om
|
||||
.readValue(new FileInputStream(configPath), VRConfig.class);
|
||||
} catch (FileNotFoundException e) {
|
||||
// Config file didn't exist, is not an error
|
||||
} catch (IOException e) {
|
||||
// Log the exception
|
||||
LogManager.severe("Config failed to load: " + e);
|
||||
// Make a backup of the erroneous config
|
||||
backupConfig();
|
||||
}
|
||||
|
||||
if (this.vrConfig == null) {
|
||||
this.vrConfig = new VRConfig();
|
||||
}
|
||||
}
|
||||
|
||||
static public void atomicMove(Path from, Path to) throws IOException {
|
||||
try {
|
||||
// Atomic move to overwrite
|
||||
Files.move(from, to, StandardCopyOption.ATOMIC_MOVE);
|
||||
} catch (AtomicMoveNotSupportedException | FileAlreadyExistsException e) {
|
||||
// Atomic move not supported or does not replace, try just replacing
|
||||
Files.move(from, to, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
}
|
||||
|
||||
public void backupConfig() {
|
||||
Path cfgFile = Paths.get(configPath);
|
||||
Path tmpBakCfgFile = Paths.get(configPath + ".bak.tmp");
|
||||
Path bakCfgFile = Paths.get(configPath + ".bak");
|
||||
|
||||
try {
|
||||
Files
|
||||
.copy(
|
||||
cfgFile,
|
||||
tmpBakCfgFile,
|
||||
StandardCopyOption.REPLACE_EXISTING,
|
||||
StandardCopyOption.COPY_ATTRIBUTES
|
||||
);
|
||||
LogManager.info("Made a backup copy of config to \"" + tmpBakCfgFile + "\"");
|
||||
} catch (IOException e) {
|
||||
LogManager
|
||||
.severe(
|
||||
"Unable to make backup copy of config from \""
|
||||
+ cfgFile
|
||||
+ "\" to \""
|
||||
+ tmpBakCfgFile
|
||||
+ "\"",
|
||||
e
|
||||
);
|
||||
return; // Abort write
|
||||
}
|
||||
|
||||
try {
|
||||
atomicMove(tmpBakCfgFile, bakCfgFile);
|
||||
} catch (IOException e) {
|
||||
LogManager
|
||||
.severe(
|
||||
"Unable to move backup config from \""
|
||||
+ tmpBakCfgFile
|
||||
+ "\" to \""
|
||||
+ bakCfgFile
|
||||
+ "\"",
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ThreadSafe
|
||||
public synchronized void saveConfig() {
|
||||
Path tmpCfgFile = Paths.get(configPath + ".tmp");
|
||||
Path cfgFile = Paths.get(configPath);
|
||||
|
||||
// Serialize config
|
||||
try {
|
||||
// delete accidental folder caused by PR
|
||||
// https://github.com/SlimeVR/SlimeVR-Server/pull/1176
|
||||
var cfgFileMaybeFolder = cfgFile.toFile();
|
||||
if (cfgFileMaybeFolder.isDirectory()) {
|
||||
try (Stream<Path> pathStream = Files.walk(cfgFile)) {
|
||||
// Can't use .toList() on Android
|
||||
var list = pathStream
|
||||
.sorted(Comparator.reverseOrder())
|
||||
.collect(Collectors.toList());
|
||||
for (var path : list) {
|
||||
Files.delete(path);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LogManager
|
||||
.severe(
|
||||
"Unable to delete folder that has same name as the config file on path \""
|
||||
+ cfgFile
|
||||
+ "\""
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
var cfgFolder = cfgFile.toAbsolutePath().getParent().toFile();
|
||||
if (!cfgFolder.exists() && !cfgFolder.mkdirs()) {
|
||||
LogManager
|
||||
.severe("Unable to create folders for config on path \"" + cfgFile + "\"");
|
||||
return;
|
||||
}
|
||||
om.writeValue(tmpCfgFile.toFile(), this.vrConfig);
|
||||
} catch (IOException e) {
|
||||
LogManager.severe("Unable to write serialized config to \"" + tmpCfgFile + "\"", e);
|
||||
return; // Abort write
|
||||
}
|
||||
|
||||
// Overwrite old config
|
||||
try {
|
||||
atomicMove(tmpCfgFile, cfgFile);
|
||||
} catch (IOException e) {
|
||||
LogManager
|
||||
.severe(
|
||||
"Unable to move new config from \"" + tmpCfgFile + "\" to \"" + cfgFile + "\"",
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public void resetConfig() {
|
||||
this.vrConfig = new VRConfig();
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
public VRConfig getVrConfig() {
|
||||
return vrConfig;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
class ConfigManager {
|
||||
private val globalConfigFile: ConfigFileHandler<GlobalConfig> = ConfigFileHandler(
|
||||
serializer = GlobalConfig.serializer(),
|
||||
currentVersion = GlobalConfig.CONFIG_VERSION,
|
||||
initDefault = { GlobalConfig() },
|
||||
migrateYamlConfig = null,
|
||||
path = "config/global.yml",
|
||||
)
|
||||
private lateinit var userConfigFile: ConfigFileHandler<UserConfig>
|
||||
private lateinit var settingsConfigFile: ConfigFileHandler<SettingsConfig>
|
||||
|
||||
init {
|
||||
global.load()
|
||||
loadCurrentProfiles()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
private fun loadCurrentSettingProfile() {
|
||||
val globalConfig = global.get()
|
||||
|
||||
settingsConfigFile = ConfigFileHandler(
|
||||
serializer = SettingsConfig.serializer(),
|
||||
currentVersion = SettingsConfig.CONFIG_VERSION,
|
||||
initDefault = { SettingsConfig() },
|
||||
migrateYamlConfig = null,
|
||||
path = "config/settings/${globalConfig.settingsProfile}.yml",
|
||||
)
|
||||
|
||||
settings.load()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
private fun loadCurrentUserProfile() {
|
||||
val globalConfig = global.get()
|
||||
|
||||
userConfigFile = ConfigFileHandler(
|
||||
serializer = UserConfig.serializer(),
|
||||
currentVersion = UserConfig.CONFIG_VERSION,
|
||||
initDefault = { UserConfig() },
|
||||
migrateYamlConfig = null,
|
||||
path = "config/user/${globalConfig.userProfile}.yml",
|
||||
)
|
||||
|
||||
user.load()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun loadCurrentProfiles() {
|
||||
loadCurrentSettingProfile()
|
||||
loadCurrentUserProfile()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
internal fun getGlobalHandler(): ConfigFileHandler<GlobalConfig> = globalConfigFile
|
||||
|
||||
@Synchronized
|
||||
internal fun getUserHandler(): ConfigFileHandler<UserConfig> = userConfigFile
|
||||
|
||||
@Synchronized
|
||||
internal fun getSettingsHandler(): ConfigFileHandler<SettingsConfig> = settingsConfigFile
|
||||
|
||||
@Synchronized
|
||||
fun saveAll() {
|
||||
globalConfigFile.save()
|
||||
userConfigFile.save()
|
||||
settingsConfigFile.save()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun switchUserProfile(newProfile: String) {
|
||||
global.updateAndSave { it.copy(userProfile = newProfile) }
|
||||
loadCurrentUserProfile()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun switchSettingsProfile(newProfile: String) {
|
||||
global.updateAndSave { it.copy(settingsProfile = newProfile) }
|
||||
loadCurrentSettingProfile()
|
||||
}
|
||||
|
||||
val global: ConfigFileHandler<GlobalConfig>
|
||||
get() = getGlobalHandler()
|
||||
|
||||
val user: ConfigFileHandler<UserConfig>
|
||||
get() = getUserHandler()
|
||||
|
||||
val settings: ConfigFileHandler<SettingsConfig>
|
||||
get() = getSettingsHandler()
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
import net.mamoe.yamlkt.YamlElement
|
||||
import net.mamoe.yamlkt.YamlList
|
||||
import net.mamoe.yamlkt.YamlLiteral
|
||||
import net.mamoe.yamlkt.YamlMap
|
||||
import java.util.regex.Pattern
|
||||
import kotlin.collections.forEach
|
||||
import kotlin.collections.set
|
||||
|
||||
// The yaml object api is very primitive as it is normally supposed to be only used by kotlinx.serialization
|
||||
// ive added some extensions to make our lives easier
|
||||
private fun YamlMap.toMutable() = this.entries.associate { it.key to it.value }.toMutableMap()
|
||||
|
||||
private operator fun Map<YamlElement, YamlElement>.get(key: String): YamlElement? = this[YamlLiteral(key)]
|
||||
|
||||
private operator fun MutableMap<YamlElement, YamlElement>.set(key: String, value: Any?) {
|
||||
if (value == null) {
|
||||
this.remove(key)
|
||||
return
|
||||
}
|
||||
this[YamlLiteral(key)] = when (value) {
|
||||
is YamlElement -> value
|
||||
is Number, is Boolean -> YamlLiteral(value.toString())
|
||||
else -> YamlLiteral(value.toString())
|
||||
}
|
||||
}
|
||||
|
||||
private fun MutableMap<YamlElement, YamlElement>.remove(key: String) = this.remove(YamlLiteral(key))
|
||||
|
||||
private fun YamlElement?.asFloat(default: Float = 0f): Float = (this as? YamlLiteral)?.content?.toFloatOrNull() ?: default
|
||||
private fun YamlElement?.asInt(default: Int = 0): Int = (this as? YamlLiteral)?.content?.toIntOrNull() ?: default
|
||||
|
||||
private fun MutableMap<YamlElement, YamlElement>.updateMap(key: String, block: MutableMap<YamlElement, YamlElement>.() -> Unit) {
|
||||
val nestedMap = (this[YamlLiteral(key)] as? YamlMap)?.toMutable() ?: mutableMapOf()
|
||||
nestedMap.block()
|
||||
this[YamlLiteral(key)] = YamlMap(nestedMap)
|
||||
}
|
||||
|
||||
fun migrateYamlConfig(modelData: YamlMap, version: Int): YamlMap {
|
||||
val config = modelData.toMutable()
|
||||
|
||||
try {
|
||||
if (version < 7) error("Config version $version is too old to be migrated.")
|
||||
|
||||
if (version < 8) {
|
||||
config.updateMap("keybindings") {
|
||||
val renaming = mapOf(
|
||||
"resetBinding" to "fullResetBinding",
|
||||
"quickResetBinding" to "yawResetBinding",
|
||||
"resetMountingBinding" to "mountingResetBinding",
|
||||
"resetDelay" to "fullResetDelay",
|
||||
"quickResetDelay" to "yawResetDelay",
|
||||
"resetMountingDelay" to "mountingResetDelay",
|
||||
)
|
||||
renaming.forEach { (old, new) ->
|
||||
this[old]?.let { value ->
|
||||
this[new] = value
|
||||
remove(old)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
config.updateMap("tapDetection") {
|
||||
listOf(
|
||||
"quickResetDelay" to "yawResetDelay",
|
||||
"resetDelay" to "fullResetDelay",
|
||||
"quickResetEnabled" to "yawResetEnabled",
|
||||
"resetEnabled" to "fullResetEnabled",
|
||||
"quickResetTaps" to "yawResetTaps",
|
||||
"resetTaps" to "fullResetTaps",
|
||||
).forEach { (old, new) ->
|
||||
this[old]?.let { this[new] = it }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (version < 9) {
|
||||
config.updateMap("skeleton") {
|
||||
this.updateMap("offsets") {
|
||||
this["chestLength"] = this["chestLength"].asFloat() / 2f
|
||||
this["upperChestLength"] = this["chestLength"].asFloat() / 2f
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (version < 10) {
|
||||
// Change default AutoBone recording length from 20 to 30
|
||||
// seconds
|
||||
config.updateMap("autoBone") {
|
||||
if (this["sampleCount"].asInt() == 1000) {
|
||||
this["sampleCount"] = 1500
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (version < 11) {
|
||||
config.updateMap("trackers") {
|
||||
updateMap("HMD") {
|
||||
this["designation"] = "body:head"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (version < 12) {
|
||||
// Update AutoBone defaults
|
||||
config.updateMap("autoBone") {
|
||||
if (this["offsetSlideErrorFactor"].asFloat() == 2.0f) {
|
||||
this["offsetSlideErrorFactor"] = 1f
|
||||
}
|
||||
if (this["bodyProportionErrorFactor"].asFloat() == 0.825f) {
|
||||
this["bodyProportionErrorFactor"] = 0.25f
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (version < 13) {
|
||||
config.updateMap("trackers") {
|
||||
val macAddressRegex = "udp://((?:[a-zA-Z\\d]{2}:){5}[a-zA-Z\\d]{2})/0"
|
||||
val pattern: Pattern = Pattern.compile(macAddressRegex)
|
||||
val devices = (config["knownDevices"] as? YamlList)?.toMutableList() ?: ArrayList()
|
||||
this.keys.forEach {
|
||||
val trackerId = it.toString()
|
||||
val matcher = pattern.matcher(trackerId)
|
||||
if (matcher.find()) {
|
||||
devices.add(YamlLiteral(matcher.group(1)))
|
||||
}
|
||||
}
|
||||
config["knownDevices"] = YamlList(devices)
|
||||
}
|
||||
}
|
||||
|
||||
if (version < 14) {
|
||||
val autoBone = config["autoBone"] as? YamlMap
|
||||
if (autoBone != null) {
|
||||
// Move HMD height from AutoBone to Skeleton
|
||||
autoBone["targetHmdHeight"]?.let { height ->
|
||||
config.updateMap("skeleton") {
|
||||
this["hmdHeight"] = height
|
||||
}
|
||||
}
|
||||
|
||||
config.updateMap("autoBone") {
|
||||
if (this["offsetSlideErrorFactor"].asFloat() == 1.0f && this["slideErrorFactor"].asFloat() == 0.0f) {
|
||||
this["offsetSlideErrorFactor"] = 0.0f
|
||||
this["slideErrorFactor"] = 1.0f
|
||||
}
|
||||
if (this["bodyProportionErrorFactor"].asFloat() == 0.25f) {
|
||||
this["bodyProportionErrorFactor"] = 0.05f
|
||||
}
|
||||
if (this["numEpochs"].asInt() == 100) {
|
||||
this["numEpochs"] = 50
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (version < 15) {
|
||||
config.updateMap("trackingChecklist") {
|
||||
this["ignoredStepsIds"] = null
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
error("Migration error: ${e.message}")
|
||||
}
|
||||
|
||||
config["modelVersion"] = SettingsConfig.CONFIG_VERSION.toString()
|
||||
|
||||
return YamlMap(config)
|
||||
}
|
||||
|
||||
fun fixTrackerKeys(input: String): String {
|
||||
val regex = """^(\s*)(udp://.*):(\s*)$""".toRegex(RegexOption.MULTILINE)
|
||||
|
||||
return input.replace(regex) { match ->
|
||||
val indent = match.groupValues[1]
|
||||
val keyPart = match.groupValues[2]
|
||||
val trailing = match.groupValues[3]
|
||||
"""$indent"$keyPart":$trailing"""
|
||||
}
|
||||
}
|
||||
@@ -1,357 +0,0 @@
|
||||
package dev.slimevr.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.*;
|
||||
import com.github.jonpeterson.jackson.module.versioning.VersionedModelConverter;
|
||||
import dev.slimevr.tracking.processor.config.SkeletonConfigOffsets;
|
||||
import dev.slimevr.tracking.trackers.TrackerPosition;
|
||||
import io.eiren.util.logging.LogManager;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
public class CurrentVRConfigConverter implements VersionedModelConverter {
|
||||
|
||||
@Override
|
||||
public ObjectNode convert(
|
||||
ObjectNode modelData,
|
||||
String modelVersion,
|
||||
String targetModelVersion,
|
||||
JsonNodeFactory nodeFactory
|
||||
) {
|
||||
try {
|
||||
int version = Integer.parseInt(modelVersion);
|
||||
|
||||
// Configs with old versions need a migration to the latest config
|
||||
if (version < 2) {
|
||||
// Move zoom to the window config
|
||||
ObjectNode windowNode = (ObjectNode) modelData.get("window");
|
||||
DoubleNode zoomNode = (DoubleNode) modelData.get("zoom");
|
||||
if (windowNode != null && zoomNode != null) {
|
||||
windowNode.set("zoom", zoomNode);
|
||||
modelData.remove("zoom");
|
||||
}
|
||||
|
||||
// Change trackers list to map
|
||||
ArrayNode oldTrackersNode = modelData.withArray("trackers");
|
||||
if (oldTrackersNode != null) {
|
||||
var trackersIter = oldTrackersNode.iterator();
|
||||
ObjectNode trackersNode = nodeFactory.objectNode();
|
||||
while (trackersIter.hasNext()) {
|
||||
JsonNode node = trackersIter.next();
|
||||
JsonNode resultNode = TrackerConfig.toV2(node, nodeFactory);
|
||||
trackersNode.set(node.get("name").asText(), resultNode);
|
||||
}
|
||||
modelData.set("trackers", trackersNode);
|
||||
}
|
||||
|
||||
// Rename bridge to bridges
|
||||
ObjectNode bridgeNode = (ObjectNode) modelData.get("bridge");
|
||||
if (bridgeNode != null) {
|
||||
modelData.set("bridges", bridgeNode);
|
||||
modelData.remove("bridge");
|
||||
}
|
||||
|
||||
// Move body to skeleton (and merge it to current skeleton)
|
||||
ObjectNode bodyNode = (ObjectNode) modelData.get("body");
|
||||
if (bodyNode != null) {
|
||||
var bodyIter = bodyNode.fields();
|
||||
ObjectNode skeletonNode = (ObjectNode) modelData.get("skeleton");
|
||||
if (skeletonNode == null) {
|
||||
skeletonNode = nodeFactory.objectNode();
|
||||
}
|
||||
|
||||
ObjectNode offsetsNode = nodeFactory.objectNode();
|
||||
while (bodyIter.hasNext()) {
|
||||
Map.Entry<String, JsonNode> node = bodyIter.next();
|
||||
// Filter only number values because other types would
|
||||
// be stuff that didn't get migrated correctly before
|
||||
if (node.getValue().isNumber()) {
|
||||
offsetsNode.set(node.getKey(), node.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
// Fix calibration wolf typos
|
||||
offsetsNode.set("shouldersWidth", bodyNode.get("shoulersWidth"));
|
||||
offsetsNode.set("shouldersDistance", bodyNode.get("shoulersDistance"));
|
||||
offsetsNode.remove("shoulersWidth");
|
||||
offsetsNode.remove("shoulersDistance");
|
||||
skeletonNode.set("offsets", offsetsNode);
|
||||
modelData.set("skeleton", skeletonNode);
|
||||
modelData.remove("body");
|
||||
}
|
||||
}
|
||||
if (version < 3) {
|
||||
// Check for out-of-bound filtering amount
|
||||
ObjectNode filtersNode = (ObjectNode) modelData.get("filters");
|
||||
if (filtersNode != null && filtersNode.get("amount").floatValue() > 2f) {
|
||||
filtersNode.set("amount", new FloatNode(0.2f));
|
||||
}
|
||||
}
|
||||
if (version < 4) {
|
||||
// Change mountingRotation to mountingOrientation
|
||||
ObjectNode oldTrackersNode = (ObjectNode) modelData.get("trackers");
|
||||
if (oldTrackersNode != null) {
|
||||
var trackersIter = oldTrackersNode.iterator();
|
||||
var fieldNamesIter = oldTrackersNode.fieldNames();
|
||||
ObjectNode trackersNode = nodeFactory.objectNode();
|
||||
String fieldName;
|
||||
while (trackersIter.hasNext()) {
|
||||
ObjectNode node = (ObjectNode) trackersIter.next();
|
||||
fieldName = fieldNamesIter.next();
|
||||
node.set("mountingOrientation", node.get("mountingRotation"));
|
||||
node.remove("mountingRotation");
|
||||
trackersNode.set(fieldName, node);
|
||||
}
|
||||
modelData.set("trackers", trackersNode);
|
||||
}
|
||||
}
|
||||
if (version < 5) {
|
||||
// Migrate old skeleton offsets to new ones
|
||||
ObjectNode skeletonNode = (ObjectNode) modelData.get("skeleton");
|
||||
if (skeletonNode != null) {
|
||||
ObjectNode offsetsNode = (ObjectNode) skeletonNode.get("offsets");
|
||||
if (offsetsNode != null) {
|
||||
// torsoLength, chestDistance and waistDistance become
|
||||
// chestLength, waistLength and hipLength.
|
||||
float torsoLength = SkeletonConfigOffsets.CHEST.defaultValue
|
||||
+ SkeletonConfigOffsets.WAIST.defaultValue
|
||||
+ SkeletonConfigOffsets.HIP.defaultValue;
|
||||
float chestDistance = SkeletonConfigOffsets.CHEST.defaultValue;
|
||||
float waistDistance = SkeletonConfigOffsets.HIP.defaultValue;
|
||||
JsonNode torsoNode = offsetsNode.get("torsoLength");
|
||||
if (torsoNode != null)
|
||||
torsoLength = torsoNode.floatValue();
|
||||
JsonNode chestNode = offsetsNode.get("chestDistance");
|
||||
if (chestNode != null)
|
||||
chestDistance = chestNode.floatValue();
|
||||
JsonNode waistNode = offsetsNode.get("waistDistance");
|
||||
if (waistNode != null)
|
||||
waistDistance = waistNode.floatValue();
|
||||
offsetsNode.set("chestLength", offsetsNode.get("chestDistance"));
|
||||
offsetsNode
|
||||
.set(
|
||||
"waistLength",
|
||||
new FloatNode(torsoLength - chestDistance - waistDistance)
|
||||
);
|
||||
offsetsNode.set("hipLength", offsetsNode.get("waistDistance"));
|
||||
offsetsNode.remove("torsoLength");
|
||||
offsetsNode.remove("chestDistance");
|
||||
offsetsNode.remove("waistDistance");
|
||||
|
||||
// legsLength and kneeHeight become
|
||||
// upperLegLength and lowerLegLength
|
||||
float legsLength = SkeletonConfigOffsets.UPPER_LEG.defaultValue
|
||||
+ SkeletonConfigOffsets.LOWER_LEG.defaultValue;
|
||||
float kneeHeight = SkeletonConfigOffsets.LOWER_LEG.defaultValue;
|
||||
JsonNode legsNode = offsetsNode.get("legsLength");
|
||||
if (legsNode != null)
|
||||
legsLength = legsNode.floatValue();
|
||||
JsonNode kneesNode = offsetsNode.get("kneeHeight");
|
||||
if (kneesNode != null)
|
||||
kneeHeight = kneesNode.floatValue();
|
||||
offsetsNode.set("upperLegLength", new FloatNode(legsLength - kneeHeight));
|
||||
offsetsNode.set("lowerLegLength", new FloatNode(kneeHeight));
|
||||
offsetsNode.remove("legsLength");
|
||||
offsetsNode.remove("kneeHeight");
|
||||
|
||||
skeletonNode.set("offsets", offsetsNode);
|
||||
modelData.set("skeleton", skeletonNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (version < 6) {
|
||||
// Migrate controllers offsets to hands offsets
|
||||
ObjectNode skeletonNode = (ObjectNode) modelData.get("skeleton");
|
||||
if (skeletonNode != null) {
|
||||
ObjectNode offsetsNode = (ObjectNode) skeletonNode.get("offsets");
|
||||
if (offsetsNode != null) {
|
||||
offsetsNode.set("handDistanceY", offsetsNode.get("controllerDistanceY"));
|
||||
offsetsNode.set("handDistanceZ", offsetsNode.get("controllerDistanceZ"));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (version < 7) {
|
||||
// Chest, hip, and elbow offsets now go the opposite direction
|
||||
ObjectNode skeletonNode = (ObjectNode) modelData.get("skeleton");
|
||||
if (skeletonNode != null) {
|
||||
ObjectNode offsetsNode = (ObjectNode) skeletonNode.get("offsets");
|
||||
if (offsetsNode != null) {
|
||||
JsonNode chestNode = offsetsNode.get("chestOffset");
|
||||
if (chestNode != null)
|
||||
offsetsNode.set("chestOffset", new FloatNode(-chestNode.floatValue()));
|
||||
JsonNode hipNode = offsetsNode.get("hipOffset");
|
||||
if (hipNode != null)
|
||||
offsetsNode.set("hipOffset", new FloatNode(-hipNode.floatValue()));
|
||||
JsonNode elbowNode = offsetsNode.get("elbowOffset");
|
||||
if (elbowNode != null)
|
||||
offsetsNode.set("elbowOffset", new FloatNode(-elbowNode.floatValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (version < 8) {
|
||||
// reset > fullReset, quickReset > yawReset
|
||||
ObjectNode keybindingsNode = (ObjectNode) modelData.get("keybindings");
|
||||
if (keybindingsNode != null) {
|
||||
JsonNode fullResetNode = keybindingsNode.get("resetBinding");
|
||||
if (fullResetNode != null)
|
||||
keybindingsNode.set("fullResetBinding", fullResetNode);
|
||||
JsonNode yawResetNode = keybindingsNode.get("quickResetBinding");
|
||||
if (yawResetNode != null)
|
||||
keybindingsNode.set("yawResetBinding", yawResetNode);
|
||||
JsonNode mountingResetNode = keybindingsNode.get("resetMountingBinding");
|
||||
if (mountingResetNode != null)
|
||||
keybindingsNode.set("mountingResetBinding", mountingResetNode);
|
||||
|
||||
JsonNode fullDelayNode = keybindingsNode.get("resetDelay");
|
||||
if (fullDelayNode != null)
|
||||
keybindingsNode.set("fullResetDelay", fullDelayNode);
|
||||
JsonNode yawDelayNode = keybindingsNode.get("quickResetDelay");
|
||||
if (yawDelayNode != null)
|
||||
keybindingsNode.set("yawResetDelay", yawDelayNode);
|
||||
JsonNode mountingDelayNode = keybindingsNode.get("resetMountingDelay");
|
||||
if (mountingDelayNode != null)
|
||||
keybindingsNode.set("mountingResetDelay", mountingDelayNode);
|
||||
}
|
||||
|
||||
ObjectNode tapDetectionNode = (ObjectNode) modelData.get("tapDetection");
|
||||
if (tapDetectionNode != null) {
|
||||
tapDetectionNode.set("yawResetDelay", tapDetectionNode.get("quickResetDelay"));
|
||||
tapDetectionNode.set("fullResetDelay", tapDetectionNode.get("resetDelay"));
|
||||
tapDetectionNode
|
||||
.set("yawResetEnabled", tapDetectionNode.get("quickResetEnabled"));
|
||||
tapDetectionNode.set("fullResetEnabled", tapDetectionNode.get("resetEnabled"));
|
||||
tapDetectionNode.set("yawResetTaps", tapDetectionNode.get("quickResetTaps"));
|
||||
tapDetectionNode.set("fullResetTaps", tapDetectionNode.get("resetTaps"));
|
||||
}
|
||||
}
|
||||
if (version < 9) {
|
||||
// split chest into 2 offsets
|
||||
ObjectNode skeletonNode = (ObjectNode) modelData.get("skeleton");
|
||||
if (skeletonNode != null) {
|
||||
ObjectNode offsetsNode = (ObjectNode) skeletonNode.get("offsets");
|
||||
if (offsetsNode != null) {
|
||||
JsonNode chestNode = offsetsNode.get("chestLength");
|
||||
if (chestNode != null) {
|
||||
offsetsNode
|
||||
.set("chestLength", new FloatNode(chestNode.floatValue() / 2f));
|
||||
offsetsNode
|
||||
.set(
|
||||
"upperChestLength",
|
||||
new FloatNode(chestNode.floatValue() / 2f)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (version < 10) {
|
||||
// Change default AutoBone recording length from 20 to 30
|
||||
// seconds
|
||||
ObjectNode autoBoneNode = (ObjectNode) modelData.get("autoBone");
|
||||
if (autoBoneNode != null) {
|
||||
JsonNode sampleCountNode = autoBoneNode.get("sampleCount");
|
||||
if (sampleCountNode != null && sampleCountNode.intValue() == 1000) {
|
||||
autoBoneNode.set("sampleCount", new IntNode(1500));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (version < 11) {
|
||||
// Sets HMD's designation to "body:head"
|
||||
ObjectNode trackersNode = (ObjectNode) modelData.get("trackers");
|
||||
if (trackersNode != null) {
|
||||
ObjectNode HMDNode = (ObjectNode) trackersNode.get("HMD");
|
||||
if (HMDNode != null) {
|
||||
HMDNode
|
||||
.set(
|
||||
"designation",
|
||||
new TextNode(TrackerPosition.HEAD.getDesignation())
|
||||
);
|
||||
trackersNode.set("HMD", HMDNode);
|
||||
modelData.set("trackers", trackersNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (version < 12) {
|
||||
// Update AutoBone defaults
|
||||
ObjectNode autoBoneNode = (ObjectNode) modelData.get("autoBone");
|
||||
if (autoBoneNode != null) {
|
||||
JsonNode offsetSlideNode = autoBoneNode.get("offsetSlideErrorFactor");
|
||||
if (offsetSlideNode != null && offsetSlideNode.floatValue() == 2.0f) {
|
||||
autoBoneNode.set("offsetSlideErrorFactor", new FloatNode(1.0f));
|
||||
}
|
||||
JsonNode bodyProportionsNode = autoBoneNode.get("bodyProportionErrorFactor");
|
||||
if (bodyProportionsNode != null && bodyProportionsNode.floatValue() == 0.825f) {
|
||||
autoBoneNode.set("bodyProportionErrorFactor", new FloatNode(0.25f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (version < 13) {
|
||||
ObjectNode oldTrackersNode = (ObjectNode) modelData.get("trackers");
|
||||
if (oldTrackersNode != null) {
|
||||
var fieldNamesIter = oldTrackersNode.fieldNames();
|
||||
String trackerId;
|
||||
final String macAddressRegex = "udp://((?:[a-zA-Z\\d]{2}:){5}[a-zA-Z\\d]{2})/0";
|
||||
final Pattern pattern = Pattern.compile(macAddressRegex);
|
||||
while (fieldNamesIter.hasNext()) {
|
||||
trackerId = fieldNamesIter.next();
|
||||
var matcher = pattern.matcher(trackerId);
|
||||
if (!matcher.find())
|
||||
continue;
|
||||
|
||||
modelData.withArray("knownDevices").add(matcher.group(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (version < 14) {
|
||||
// Update AutoBone defaults
|
||||
ObjectNode autoBoneNode = (ObjectNode) modelData.get("autoBone");
|
||||
if (autoBoneNode != null) {
|
||||
// Move HMD height to skeleton
|
||||
ObjectNode skeletonNode = (ObjectNode) modelData.get("skeleton");
|
||||
if (skeletonNode != null) {
|
||||
JsonNode targetHmdHeight = autoBoneNode.get("targetHmdHeight");
|
||||
if (targetHmdHeight != null) {
|
||||
skeletonNode.set("hmdHeight", targetHmdHeight);
|
||||
}
|
||||
}
|
||||
|
||||
JsonNode offsetSlideNode = autoBoneNode.get("offsetSlideErrorFactor");
|
||||
JsonNode slideNode = autoBoneNode.get("slideErrorFactor");
|
||||
if (
|
||||
offsetSlideNode != null
|
||||
&& slideNode != null
|
||||
&& offsetSlideNode.floatValue() == 1.0f
|
||||
&& slideNode.floatValue() == 0.0f
|
||||
) {
|
||||
autoBoneNode.set("offsetSlideErrorFactor", new FloatNode(0.0f));
|
||||
autoBoneNode.set("slideErrorFactor", new FloatNode(1.0f));
|
||||
}
|
||||
JsonNode bodyProportionsNode = autoBoneNode.get("bodyProportionErrorFactor");
|
||||
if (bodyProportionsNode != null && bodyProportionsNode.floatValue() == 0.25f) {
|
||||
autoBoneNode.set("bodyProportionErrorFactor", new FloatNode(0.05f));
|
||||
}
|
||||
JsonNode numEpochsNode = autoBoneNode.get("numEpochs");
|
||||
if (numEpochsNode != null && numEpochsNode.intValue() == 100) {
|
||||
autoBoneNode.set("numEpochs", new IntNode(50));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (version < 15) {
|
||||
ObjectNode checklistNode = (ObjectNode) modelData.get("trackingChecklist");
|
||||
if (checklistNode != null) {
|
||||
ArrayNode ignoredStepsArray = (ArrayNode) checklistNode.get("ignoredStepsIds");
|
||||
if (ignoredStepsArray != null)
|
||||
ignoredStepsArray.removeAll();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogManager.severe("Error during config migration: " + e);
|
||||
}
|
||||
|
||||
return modelData;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
import dev.slimevr.VRServer
|
||||
|
||||
class DriftCompensationConfig {
|
||||
|
||||
// Is drift compensation enabled
|
||||
var enabled = false
|
||||
|
||||
// Is drift prediction enabled
|
||||
var prediction = false
|
||||
|
||||
// Amount of drift compensation applied
|
||||
var amount = 0.8f
|
||||
|
||||
// Max resets for the calculated average drift
|
||||
var maxResets = 6
|
||||
|
||||
fun updateTrackersDriftCompensation() {
|
||||
for (t in VRServer.instance.allTrackers) {
|
||||
if (t.isImu()) {
|
||||
t.resetsHandler.readDriftCompensationConfig(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,20 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
import dev.slimevr.VRServer
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
class FiltersConfig {
|
||||
|
||||
@Serializable
|
||||
data class FiltersConfig(
|
||||
// Type of filtering applied (none, smoothing or prediction)
|
||||
var type = "prediction"
|
||||
|
||||
val type: String = "prediction",
|
||||
// Amount/Intensity of the specified filtering (0 to 1)
|
||||
var amount = 0.2f
|
||||
|
||||
fun updateTrackersFilters() {
|
||||
for (tracker in VRServer.instance.allTrackers) {
|
||||
if (tracker.allowFiltering) {
|
||||
tracker.filteringHandler.readFilteringConfig(this, tracker.getRotation())
|
||||
}
|
||||
}
|
||||
}
|
||||
val amount: Float = 0.2f,
|
||||
) {
|
||||
// fun updateTrackersFilters() {
|
||||
// for (tracker in VRServer.instance.allTrackers) {
|
||||
// if (tracker.allowFiltering) {
|
||||
// tracker.filteringHandler.readFilteringConfig(this, tracker.getRotation())
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class GlobalConfig(
|
||||
val userProfile: String = "default",
|
||||
val settingsProfile: String = "default",
|
||||
val version: String = CONFIG_VERSION.toString(),
|
||||
) {
|
||||
companion object {
|
||||
const val CONFIG_VERSION = 1
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
class HIDConfig {
|
||||
var trackersOverHID = false
|
||||
}
|
||||
@Serializable
|
||||
data class HIDConfig(
|
||||
val trackersOverHID: Boolean = false,
|
||||
)
|
||||
@@ -1,72 +0,0 @@
|
||||
package dev.slimevr.config;
|
||||
|
||||
public class KeybindingsConfig {
|
||||
|
||||
private String fullResetBinding = "CTRL+ALT+SHIFT+Y";
|
||||
|
||||
private String yawResetBinding = "CTRL+ALT+SHIFT+U";
|
||||
|
||||
private String mountingResetBinding = "CTRL+ALT+SHIFT+I";
|
||||
|
||||
private String pauseTrackingBinding = "CTRL+ALT+SHIFT+O";
|
||||
|
||||
private long fullResetDelay = 0L;
|
||||
|
||||
private long yawResetDelay = 0L;
|
||||
|
||||
private long mountingResetDelay = 0L;
|
||||
|
||||
private long pauseTrackingDelay = 0L;
|
||||
|
||||
|
||||
public KeybindingsConfig() {
|
||||
}
|
||||
|
||||
public String getFullResetBinding() {
|
||||
return fullResetBinding;
|
||||
}
|
||||
|
||||
public String getYawResetBinding() {
|
||||
return yawResetBinding;
|
||||
}
|
||||
|
||||
public String getMountingResetBinding() {
|
||||
return mountingResetBinding;
|
||||
}
|
||||
|
||||
public String getPauseTrackingBinding() {
|
||||
return pauseTrackingBinding;
|
||||
}
|
||||
|
||||
public long getFullResetDelay() {
|
||||
return fullResetDelay;
|
||||
}
|
||||
|
||||
public void setFullResetDelay(long delay) {
|
||||
fullResetDelay = delay;
|
||||
}
|
||||
|
||||
public long getYawResetDelay() {
|
||||
return yawResetDelay;
|
||||
}
|
||||
|
||||
public void setYawResetDelay(long delay) {
|
||||
yawResetDelay = delay;
|
||||
}
|
||||
|
||||
public long getMountingResetDelay() {
|
||||
return mountingResetDelay;
|
||||
}
|
||||
|
||||
public void setMountingResetDelay(long delay) {
|
||||
mountingResetDelay = delay;
|
||||
}
|
||||
|
||||
public long getPauseTrackingDelay() {
|
||||
return pauseTrackingDelay;
|
||||
}
|
||||
|
||||
public void setPauseTrackingDelay(long delay) {
|
||||
pauseTrackingDelay = delay;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class KeybindingsConfig(
|
||||
val fullResetBinding: String = "CTRL+ALT+SHIFT+Y",
|
||||
val yawResetBinding: String = "CTRL+ALT+SHIFT+U",
|
||||
val mountingResetBinding: String = "CTRL+ALT+SHIFT+I",
|
||||
val pauseTrackingBinding: String = "CTRL+ALT+SHIFT+O",
|
||||
val fullResetDelay: Long = 0L,
|
||||
val yawResetDelay: Long = 0L,
|
||||
val mountingResetDelay: Long = 0L,
|
||||
val pauseTrackingDelay: Long = 0L,
|
||||
)
|
||||
@@ -1,6 +1,9 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
class LegTweaksConfig {
|
||||
var correctionStrength = 0.3f
|
||||
var alwaysUseFloorclip = false
|
||||
}
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class LegTweaksConfig(
|
||||
val correctionStrength: Float = 0.3f,
|
||||
val alwaysUseFloorclip: Boolean = false,
|
||||
)
|
||||
@@ -1,16 +1,15 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
open class OSCConfig {
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class OSCConfig(
|
||||
// Are the OSC receiver and sender enabled?
|
||||
var enabled = false
|
||||
|
||||
val enabled: Boolean = false,
|
||||
// Port to receive OSC messages from
|
||||
var portIn = 0
|
||||
|
||||
val portIn: Int = 9002,
|
||||
// Port to send out OSC messages at
|
||||
var portOut = 0
|
||||
|
||||
val portOut: Int = 9000,
|
||||
// Address to send out OSC messages at
|
||||
var address = "127.0.0.1"
|
||||
}
|
||||
val address: String = "127.0.0.1",
|
||||
)
|
||||
@@ -1,24 +0,0 @@
|
||||
package dev.slimevr.config;
|
||||
|
||||
public class OverlayConfig {
|
||||
|
||||
private boolean isMirrored = false;
|
||||
private boolean isVisible = false;
|
||||
|
||||
|
||||
public boolean isMirrored() {
|
||||
return isMirrored;
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
return isVisible;
|
||||
}
|
||||
|
||||
public void setMirrored(boolean mirrored) {
|
||||
isMirrored = mirrored;
|
||||
}
|
||||
|
||||
public void setVisible(boolean visible) {
|
||||
isVisible = visible;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class OverlayConfig(
|
||||
val isMirrored: Boolean = false,
|
||||
val isVisible: Boolean = false,
|
||||
)
|
||||
@@ -1,8 +1,8 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
import dev.slimevr.VRServer
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
enum class ArmsResetModes(val id: Int) {
|
||||
enum class ArmsResetMode(val id: Int) {
|
||||
// Upper arm going back and forearm going forward
|
||||
BACK(0),
|
||||
|
||||
@@ -20,7 +20,7 @@ enum class ArmsResetModes(val id: Int) {
|
||||
val values = entries.toTypedArray()
|
||||
|
||||
@JvmStatic
|
||||
fun fromId(id: Int): ArmsResetModes? {
|
||||
fun fromId(id: Int): ArmsResetMode? {
|
||||
for (filter in values) {
|
||||
if (filter.id == id) return filter
|
||||
}
|
||||
@@ -29,16 +29,16 @@ enum class ArmsResetModes(val id: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
enum class MountingMethods(val id: Int) {
|
||||
enum class MountingMethod(val id: Int) {
|
||||
MANUAL(0),
|
||||
AUTOMATIC(1),
|
||||
;
|
||||
|
||||
companion object {
|
||||
val values = MountingMethods.entries.toTypedArray()
|
||||
val values = MountingMethod.entries.toTypedArray()
|
||||
|
||||
@JvmStatic
|
||||
fun fromId(id: Int): MountingMethods? {
|
||||
fun fromId(id: Int): MountingMethod? {
|
||||
for (filter in values) {
|
||||
if (filter.id == id) return filter
|
||||
}
|
||||
@@ -47,32 +47,32 @@ enum class MountingMethods(val id: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
class ResetsConfig {
|
||||
|
||||
@Serializable
|
||||
data class ResetsConfig(
|
||||
// Always reset mounting for feet
|
||||
var resetMountingFeet = false
|
||||
val resetMountingFeet: Boolean = false,
|
||||
|
||||
// Reset mode used for the arms
|
||||
var mode = ArmsResetModes.BACK
|
||||
val mode: ArmsResetMode = ArmsResetMode.BACK,
|
||||
|
||||
// Yaw reset smoothing time in seconds
|
||||
var yawResetSmoothTime = 0.0f
|
||||
val yawResetSmoothTime: Float = 0.0f,
|
||||
|
||||
// Save automatic mounting reset calibration
|
||||
var saveMountingReset = false
|
||||
val saveMountingReset: Boolean = false,
|
||||
|
||||
// Reset the HMD's pitch upon full reset
|
||||
var resetHmdPitch = false
|
||||
val resetHmdPitch: Boolean = false,
|
||||
|
||||
var lastMountingMethod = MountingMethods.AUTOMATIC
|
||||
val lastMountingMethod: MountingMethod = MountingMethod.AUTOMATIC,
|
||||
|
||||
var yawResetDelay = 0.0f
|
||||
var fullResetDelay = 3.0f
|
||||
var mountingResetDelay = 3.0f
|
||||
|
||||
fun updateTrackersResetsSettings() {
|
||||
for (t in VRServer.instance.allTrackers) {
|
||||
t.resetsHandler.readResetConfig(this)
|
||||
}
|
||||
}
|
||||
val yawResetDelay: Float = 0.0f,
|
||||
val fullResetDelay: Float = 3.0f,
|
||||
val mountingResetDelay: Float = 3.0f,
|
||||
) {
|
||||
// fun updateTrackersResetsSettings() {
|
||||
// for (t in VRServer.instance.allTrackers) {
|
||||
// t.resetsHandler.readResetConfig(this)
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@@ -6,61 +6,66 @@ import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.awaitAll
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.Transient
|
||||
|
||||
class ServerConfig {
|
||||
val trackerPort: Int = 6969
|
||||
|
||||
var useMagnetometerOnAllTrackers: Boolean = false
|
||||
private set
|
||||
|
||||
private val magMutex = Mutex()
|
||||
suspend fun defineMagOnAllTrackers(state: Boolean) = coroutineScope {
|
||||
magMutex.lock()
|
||||
try {
|
||||
if (useMagnetometerOnAllTrackers == state) return@coroutineScope
|
||||
|
||||
VRServer.instance.deviceManager.devices.filter { it.magSupport }.map {
|
||||
async {
|
||||
// Not using 255 as it sometimes could make one of the sensors go into
|
||||
// error mode (if there is more than one sensor inside the device)
|
||||
if (!state) {
|
||||
val trackers = it.trackers.filterValues {
|
||||
it.magStatus != MagnetometerStatus.NOT_SUPPORTED
|
||||
}
|
||||
// if(trackers.size == it.trackers.size) {
|
||||
// it.setMag(false)
|
||||
// } else {
|
||||
trackers.map { (_, t) ->
|
||||
async { it.setMag(false, t.trackerNum) }
|
||||
}.awaitAll()
|
||||
@Serializable
|
||||
data class ServerConfig(
|
||||
val trackerPort: Int = 6969,
|
||||
val useMagnetometerOnAllTrackers: Boolean = false,
|
||||
) {
|
||||
// var useMagnetometerOnAllTrackers: Boolean = false
|
||||
// private set
|
||||
//
|
||||
// @Transient
|
||||
// private val magMutex = Mutex()
|
||||
// suspend fun defineMagOnAllTrackers(state: Boolean) = coroutineScope {
|
||||
// magMutex.lock()
|
||||
// try {
|
||||
// if (useMagnetometerOnAllTrackers == state) return@coroutineScope
|
||||
//
|
||||
// VRServer.instance.deviceManager.devices.filter { it.magSupport }.map {
|
||||
// async {
|
||||
// // Not using 255 as it sometimes could make one of the sensors go into
|
||||
// // error mode (if there is more than one sensor inside the device)
|
||||
// if (!state) {
|
||||
// val trackers = it.trackers.filterValues {
|
||||
// it.magStatus != MagnetometerStatus.NOT_SUPPORTED
|
||||
// }
|
||||
return@async
|
||||
}
|
||||
|
||||
// val every = it.trackers.all { (_, t) -> t.config.shouldHaveMagEnabled == true
|
||||
// && t.magStatus != MagnetometerStatus.NOT_SUPPORTED }
|
||||
// if (every) {
|
||||
// it.setMag(true)
|
||||
// // if(trackers.size == it.trackers.size) {
|
||||
// // it.setMag(false)
|
||||
// // } else {
|
||||
// trackers.map { (_, t) ->
|
||||
// async { it.setMag(false, t.trackerNum) }
|
||||
// }.awaitAll()
|
||||
// // }
|
||||
// return@async
|
||||
// }
|
||||
|
||||
it.trackers.filterValues {
|
||||
it.config.shouldHaveMagEnabled == true &&
|
||||
it.magStatus != MagnetometerStatus.NOT_SUPPORTED
|
||||
}
|
||||
.map { (_, t) ->
|
||||
async {
|
||||
// FIXME: Tracker gets restarted after each setMag, what will happen for devices with 3 trackers?
|
||||
it.setMag(true, t.trackerNum)
|
||||
}
|
||||
}.awaitAll()
|
||||
}
|
||||
}.awaitAll()
|
||||
|
||||
useMagnetometerOnAllTrackers = state
|
||||
VRServer.instance.configManager.saveConfig()
|
||||
} finally {
|
||||
magMutex.unlock()
|
||||
}
|
||||
}
|
||||
//
|
||||
// // val every = it.trackers.all { (_, t) -> t.config.shouldHaveMagEnabled == true
|
||||
// // && t.magStatus != MagnetometerStatus.NOT_SUPPORTED }
|
||||
// // if (every) {
|
||||
// // it.setMag(true)
|
||||
// // return@async
|
||||
// // }
|
||||
//
|
||||
// it.trackers.filterValues {
|
||||
// it.config.shouldHaveMagEnabled == true &&
|
||||
// it.magStatus != MagnetometerStatus.NOT_SUPPORTED
|
||||
// }
|
||||
// .map { (_, t) ->
|
||||
// async {
|
||||
// // FIXME: Tracker gets restarted after each setMag, what will happen for devices with 3 trackers?
|
||||
// it.setMag(true, t.trackerNum)
|
||||
// }
|
||||
// }.awaitAll()
|
||||
// }
|
||||
// }.awaitAll()
|
||||
//
|
||||
// useMagnetometerOnAllTrackers = state
|
||||
// VRServer.instance.configManager.saveConfig()
|
||||
// } finally {
|
||||
// magMutex.unlock()
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class SettingsConfig(
|
||||
val server: ServerConfig = ServerConfig(),
|
||||
val filters: FiltersConfig = FiltersConfig(),
|
||||
val oscRouter: OSCConfig = OSCConfig(),
|
||||
val vrcOSC: VRCOSCConfig = VRCOSCConfig(),
|
||||
val vmc: VMCConfig = VMCConfig(),
|
||||
val autoBone: AutoBoneConfig = AutoBoneConfig(),
|
||||
val keybindings: KeybindingsConfig = KeybindingsConfig(),
|
||||
val legTweaks: LegTweaksConfig = LegTweaksConfig(),
|
||||
val tapDetection: TapDetectionConfig = TapDetectionConfig(),
|
||||
val resetsConfig: ResetsConfig = ResetsConfig(),
|
||||
val stayAlignedConfig: StayAlignedConfig = StayAlignedConfig(),
|
||||
val hidConfig: HIDConfig = HIDConfig(),
|
||||
val bridges: Map<String, BridgeConfig> = HashMap(),
|
||||
val knownDevices: Set<String> = setOf(),
|
||||
val overlay: OverlayConfig = OverlayConfig(),
|
||||
val trackingChecklist: TrackingChecklistConfig = TrackingChecklistConfig(),
|
||||
val vrcConfig: VRCConfig = VRCConfig(),
|
||||
val version: Int = CONFIG_VERSION,
|
||||
) {
|
||||
// fun getTracker(tracker: Tracker): TrackerConfig {
|
||||
// var config = trackers[tracker.name]
|
||||
// if (config == null) {
|
||||
// config = TrackerConfig(tracker)
|
||||
// trackers[tracker.name] = config
|
||||
// }
|
||||
// return config
|
||||
// }
|
||||
//
|
||||
// fun readTrackerConfig(tracker: Tracker) {
|
||||
// if (tracker.userEditable) {
|
||||
// val config = getTracker(tracker)
|
||||
// tracker.readConfig(config)
|
||||
// tracker.resetsHandler.readResetConfig(resetsConfig)
|
||||
// if (tracker.allowReset) {
|
||||
// tracker.saveMountingResetOrientation(config)
|
||||
// }
|
||||
// if (tracker.allowFiltering) {
|
||||
// tracker
|
||||
// .filteringHandler
|
||||
// .readFilteringConfig(filters, tracker.getRotation())
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// fun writeTrackerConfig(tracker: Tracker?) {
|
||||
// if (tracker?.userEditable == true) {
|
||||
// val tc = getTracker(tracker)
|
||||
// tracker.writeConfig(tc)
|
||||
// }
|
||||
// }
|
||||
|
||||
// fun getBridge(bridgeKey: String): BridgeConfig {
|
||||
// var config = bridges[bridgeKey]
|
||||
// if (config == null) {
|
||||
// config = BridgeConfig()
|
||||
// bridges[bridgeKey] = config
|
||||
// }
|
||||
// return config
|
||||
// }
|
||||
|
||||
fun isKnownDevice(mac: String?): Boolean = knownDevices.contains(mac)
|
||||
|
||||
// fun addKnownDevice(mac: String): Boolean = knownDevices.add(mac)
|
||||
|
||||
// fun forgetKnownDevice(mac: String): Boolean = knownDevices.remove(mac)
|
||||
|
||||
companion object {
|
||||
const val CONFIG_VERSION = 15
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package dev.slimevr.config;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.StdKeySerializers;
|
||||
import dev.slimevr.config.serializers.BooleanMapDeserializer;
|
||||
import dev.slimevr.config.serializers.FloatMapDeserializer;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class SkeletonConfig {
|
||||
|
||||
@JsonDeserialize(using = BooleanMapDeserializer.class)
|
||||
@JsonSerialize(keyUsing = StdKeySerializers.StringKeySerializer.class)
|
||||
public Map<String, Boolean> toggles = new HashMap<>();
|
||||
|
||||
@JsonDeserialize(using = FloatMapDeserializer.class)
|
||||
@JsonSerialize(keyUsing = StdKeySerializers.StringKeySerializer.class)
|
||||
public Map<String, Float> values = new HashMap<>();
|
||||
|
||||
@JsonDeserialize(using = FloatMapDeserializer.class)
|
||||
@JsonSerialize(keyUsing = StdKeySerializers.StringKeySerializer.class)
|
||||
public Map<String, Float> offsets = new HashMap<>();
|
||||
|
||||
private float hmdHeight = 0f;
|
||||
private float floorHeight = 0f;
|
||||
|
||||
public Map<String, Boolean> getToggles() {
|
||||
return toggles;
|
||||
}
|
||||
|
||||
public Map<String, Float> getOffsets() {
|
||||
return offsets;
|
||||
}
|
||||
|
||||
public Map<String, Float> getValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
public float getHmdHeight() {
|
||||
return hmdHeight;
|
||||
}
|
||||
|
||||
public void setHmdHeight(float hmdHeight) {
|
||||
this.hmdHeight = hmdHeight;
|
||||
}
|
||||
|
||||
public float getFloorHeight() {
|
||||
return floorHeight;
|
||||
}
|
||||
|
||||
public void setFloorHeight(float hmdHeight) {
|
||||
this.floorHeight = hmdHeight;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public float getUserHeight() {
|
||||
return hmdHeight - floorHeight;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.Transient
|
||||
@Serializable
|
||||
data class SkeletonConfig(
|
||||
val toggles: MutableMap<String, Boolean> = HashMap(),
|
||||
val values: MutableMap<String, Float> = HashMap(),
|
||||
val offsets: MutableMap<String, Float> = HashMap(),
|
||||
@JvmField val hmdHeight: Float = 0f,
|
||||
@JvmField val floorHeight: Float = 0f,
|
||||
) {
|
||||
@Transient
|
||||
val userHeight: Float
|
||||
get() = hmdHeight - floorHeight
|
||||
}
|
||||
@@ -1,44 +1,42 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||
|
||||
class StayAlignedConfig {
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class StayAlignedConfig(
|
||||
/**
|
||||
* Apply yaw correction
|
||||
*/
|
||||
var enabled = false
|
||||
|
||||
/**
|
||||
* Temporarily hide the yaw correction from Stay Aligned.
|
||||
*
|
||||
* Players can enable this to compare to when Stay Aligned is not enabled. Useful to
|
||||
* verify if Stay Aligned improved the situation. Also useful to prevent players
|
||||
* from saying "Stay Aligned screwed up my trackers!!" when it's actually a tracker
|
||||
* that is drifting extremely badly.
|
||||
*
|
||||
* Do not serialize to config so that when the server restarts, it is always false.
|
||||
*/
|
||||
@JsonIgnore
|
||||
var hideYawCorrection = false
|
||||
val enabled: Boolean = false,
|
||||
|
||||
// /**
|
||||
// * Temporarily hide the yaw correction from Stay Aligned.
|
||||
// *
|
||||
// * Players can enable this to compare to when Stay Aligned is not enabled. Useful to
|
||||
// * verify if Stay Aligned improved the situation. Also useful to prevent players
|
||||
// * from saying "Stay Aligned screwed up my trackers!!" when it's actually a tracker
|
||||
// * that is drifting extremely badly.
|
||||
// *
|
||||
// * Do not serialize to config so that when the server restarts, it is always false.
|
||||
// */
|
||||
// @Transient var hideYawCorrection: Boolean = false,
|
||||
/**
|
||||
* Standing relaxed pose
|
||||
*/
|
||||
val standingRelaxedPose = StayAlignedRelaxedPoseConfig()
|
||||
val standingRelaxedPose: StayAlignedRelaxedPoseConfig = StayAlignedRelaxedPoseConfig(),
|
||||
|
||||
/**
|
||||
* Sitting relaxed pose
|
||||
*/
|
||||
val sittingRelaxedPose = StayAlignedRelaxedPoseConfig()
|
||||
val sittingRelaxedPose: StayAlignedRelaxedPoseConfig = StayAlignedRelaxedPoseConfig(),
|
||||
|
||||
/**
|
||||
* Flat relaxed pose
|
||||
*/
|
||||
val flatRelaxedPose = StayAlignedRelaxedPoseConfig()
|
||||
val flatRelaxedPose: StayAlignedRelaxedPoseConfig = StayAlignedRelaxedPoseConfig(),
|
||||
|
||||
/**
|
||||
* Whether setup has been completed
|
||||
*/
|
||||
var setupComplete = false
|
||||
}
|
||||
val setupComplete: Boolean = false,
|
||||
)
|
||||
@@ -1,25 +1,27 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
class StayAlignedRelaxedPoseConfig {
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class StayAlignedRelaxedPoseConfig(
|
||||
/**
|
||||
* Whether Stay Aligned should adjust the tracker yaws when the player is in this
|
||||
* pose.
|
||||
*/
|
||||
var enabled = false
|
||||
val enabled: Boolean = false,
|
||||
|
||||
/**
|
||||
* Angle between the upper leg yaw and the center yaw.
|
||||
*/
|
||||
var upperLegAngleInDeg = 0.0f
|
||||
val upperLegAngleInDeg: Float = 0.0f,
|
||||
|
||||
/**
|
||||
* Angle between the lower leg yaw and the center yaw.
|
||||
*/
|
||||
var lowerLegAngleInDeg = 0.0f
|
||||
val lowerLegAngleInDeg: Float = 0.0f,
|
||||
|
||||
/**
|
||||
* Angle between the foot and the center yaw.
|
||||
*/
|
||||
var footAngleInDeg = 0.0f
|
||||
}
|
||||
val footAngleInDeg: Float = 0.0f,
|
||||
)
|
||||
@@ -1,29 +1,22 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
import com.jme3.math.FastMath
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
// handles the tap detection config
|
||||
// this involves the number of taps, the delay, and whether or not the feature is enabled
|
||||
// for each reset type
|
||||
class TapDetectionConfig {
|
||||
var yawResetDelay = 0.2f
|
||||
var fullResetDelay = 1.0f
|
||||
var mountingResetDelay = 1.0f
|
||||
var yawResetEnabled = true
|
||||
var fullResetEnabled = true
|
||||
var mountingResetEnabled = true
|
||||
var setupMode = false
|
||||
var yawResetTaps = 2
|
||||
set(yawResetTaps) {
|
||||
field = yawResetTaps.coerceIn(2, 10)
|
||||
}
|
||||
var fullResetTaps = 3
|
||||
set(fullResetTaps) {
|
||||
field = fullResetTaps.coerceIn(2, 10)
|
||||
}
|
||||
var mountingResetTaps = 3
|
||||
set(mountingResetTaps) {
|
||||
field = mountingResetTaps.coerceIn(2, 10)
|
||||
}
|
||||
var numberTrackersOverThreshold = 1
|
||||
}
|
||||
@Serializable
|
||||
data class TapDetectionConfig(
|
||||
val yawResetDelay: Float = 0.2f,
|
||||
val fullResetDelay: Float = 1.0f,
|
||||
val mountingResetDelay: Float = 1.0f,
|
||||
val yawResetEnabled: Boolean = true,
|
||||
val fullResetEnabled: Boolean = true,
|
||||
val setupMode: Boolean = false,
|
||||
val mountingResetEnabled: Boolean = true,
|
||||
val yawResetTaps: Int = 2,
|
||||
val fullResetTaps: Int = 3,
|
||||
val mountingResetTaps: Int = 3,
|
||||
val numberTrackersOverThreshold: Int = 1,
|
||||
)
|
||||
@@ -1,49 +1,33 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory
|
||||
import dev.slimevr.VRServer
|
||||
import dev.slimevr.config.serializers.QuaternionSerializer
|
||||
import dev.slimevr.tracking.trackers.Tracker
|
||||
import io.github.axisangles.ktmath.ObjectQuaternion
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
class TrackerConfig {
|
||||
var customName: String? = null
|
||||
var designation: String? = null
|
||||
|
||||
@get:JvmName("isHide")
|
||||
var hide: Boolean = false
|
||||
var adjustment: ObjectQuaternion? = null
|
||||
@Serializable(with = QuaternionSerializer::class)
|
||||
var mountingOrientation: ObjectQuaternion? = null
|
||||
|
||||
@Serializable(with = QuaternionSerializer::class)
|
||||
var mountingResetOrientation: ObjectQuaternion? = null
|
||||
var allowDriftCompensation: Boolean? = null
|
||||
|
||||
/**
|
||||
* Only checked if [ServerConfig.useMagnetometerOnAllTrackers] enabled
|
||||
*/
|
||||
var shouldHaveMagEnabled: Boolean? = null
|
||||
|
||||
constructor()
|
||||
|
||||
constructor(tracker: Tracker) {
|
||||
this.designation = if (tracker.trackerPosition != null) tracker.trackerPosition!!.designation else null
|
||||
this.customName = tracker.customName
|
||||
allowDriftCompensation = tracker.isImu()
|
||||
shouldHaveMagEnabled = tracker.isImu()
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun toV2(v1: JsonNode, factory: JsonNodeFactory): JsonNode {
|
||||
val node = factory.objectNode()
|
||||
if (v1.has("customName")) node.set<JsonNode>("customName", v1["customName"])
|
||||
if (v1.has("designation")) node.set<JsonNode>("designation", v1["designation"])
|
||||
if (v1.has("hide")) node.set<JsonNode>("hide", v1["hide"])
|
||||
if (v1.has("mountingRotation")) node.set<JsonNode>("mountingRotation", v1["mountingRotation"])
|
||||
if (v1.has("adjustment")) node.set<JsonNode>("adjustment", v1["adjustment"])
|
||||
return node
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val Tracker.config: TrackerConfig
|
||||
get() = VRServer.instance.configManager.vrConfig.getTracker(this)
|
||||
// val Tracker.config: TrackerConfig
|
||||
// get() = VRServer.instance.configManager.vrConfig.getTracker(this)
|
||||
@@ -1,5 +1,8 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
class TrackingChecklistConfig {
|
||||
val ignoredStepsIds: MutableList<Int> = mutableListOf()
|
||||
}
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class TrackingChecklistConfig(
|
||||
val ignoredStepsIds: List<Int> = listOf(),
|
||||
)
|
||||
@@ -0,0 +1,14 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class UserConfig(
|
||||
val skeleton: SkeletonConfig = SkeletonConfig(),
|
||||
val trackers: Map<String, TrackerConfig> = HashMap(),
|
||||
val version: Int = CONFIG_VERSION,
|
||||
) {
|
||||
companion object {
|
||||
const val CONFIG_VERSION = 1
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,27 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
class VMCConfig : OSCConfig() {
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class VMCConfig(
|
||||
// Are the OSC receiver and sender enabled?
|
||||
val enabled: Boolean = false,
|
||||
|
||||
// Port to receive OSC messages from
|
||||
val portIn: Int = 39540,
|
||||
|
||||
// Port to send out OSC messages at
|
||||
val portOut: Int = 39539,
|
||||
|
||||
// Address to send out OSC messages at
|
||||
val address: String = "127.0.0.1",
|
||||
|
||||
// Anchor the tracking at the hip?
|
||||
var anchorHip = true
|
||||
val anchorHip: Boolean = true,
|
||||
|
||||
// JSON part of the VRM to be used
|
||||
var vrmJson: String? = null
|
||||
val vrmJson: String? = null,
|
||||
|
||||
// Mirror the tracking before sending it (turn left <=> turn right, left leg <=> right leg)
|
||||
var mirrorTracking = false
|
||||
}
|
||||
val mirrorTracking: Boolean = false,
|
||||
)
|
||||
@@ -1,6 +1,9 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
class VRCConfig {
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class VRCConfig(
|
||||
// List of fields ignored in vrc warnings - @see VRCConfigValidity
|
||||
val mutedWarnings: MutableList<String> = mutableListOf()
|
||||
}
|
||||
val mutedWarnings: MutableList<String> = mutableListOf(),
|
||||
)
|
||||
@@ -1,24 +1,22 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize
|
||||
import com.fasterxml.jackson.databind.ser.std.StdKeySerializers
|
||||
import dev.slimevr.config.serializers.BooleanMapDeserializer
|
||||
import dev.slimevr.tracking.trackers.TrackerRole
|
||||
import java.util.*
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
class VRCOSCConfig : OSCConfig() {
|
||||
@Serializable
|
||||
data class VRCOSCConfig(
|
||||
// Are the OSC receiver and sender enabled?
|
||||
val enabled: Boolean = false,
|
||||
|
||||
// Which trackers' data to send
|
||||
@JsonDeserialize(using = BooleanMapDeserializer::class)
|
||||
@JsonSerialize(keyUsing = StdKeySerializers.StringKeySerializer::class)
|
||||
var trackers: MutableMap<String, Boolean> = HashMap()
|
||||
// Port to receive OSC messages from
|
||||
val portIn: Int = 9001,
|
||||
|
||||
var oscqueryEnabled: Boolean = true
|
||||
// Port to send out OSC messages at
|
||||
val portOut: Int = 9000,
|
||||
|
||||
fun getOSCTrackerRole(role: TrackerRole, def: Boolean): Boolean = trackers.getOrDefault(role.name.lowercase(Locale.getDefault()), def)
|
||||
// Address to send out OSC messages at
|
||||
val address: String = "127.0.0.1",
|
||||
|
||||
fun setOSCTrackerRole(role: TrackerRole, `val`: Boolean) {
|
||||
trackers[role.name.lowercase(Locale.getDefault())] = `val`
|
||||
}
|
||||
}
|
||||
val trackers: MutableMap<String, Boolean> = HashMap(),
|
||||
|
||||
val oscqueryEnabled: Boolean = true,
|
||||
)
|
||||
@@ -1,145 +0,0 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize
|
||||
import com.fasterxml.jackson.databind.ser.std.StdKeySerializers
|
||||
import com.github.jonpeterson.jackson.module.versioning.JsonVersionedModel
|
||||
import dev.slimevr.config.serializers.BridgeConfigMapDeserializer
|
||||
import dev.slimevr.config.serializers.TrackerConfigMapDeserializer
|
||||
import dev.slimevr.tracking.trackers.Tracker
|
||||
import dev.slimevr.tracking.trackers.TrackerRole
|
||||
|
||||
@JsonVersionedModel(
|
||||
currentVersion = "15",
|
||||
defaultDeserializeToVersion = "15",
|
||||
toCurrentConverterClass = CurrentVRConfigConverter::class,
|
||||
)
|
||||
class VRConfig {
|
||||
val server: ServerConfig = ServerConfig()
|
||||
|
||||
val filters: FiltersConfig = FiltersConfig()
|
||||
|
||||
val driftCompensation: DriftCompensationConfig = DriftCompensationConfig()
|
||||
|
||||
val oscRouter: OSCConfig = OSCConfig()
|
||||
|
||||
val vrcOSC: VRCOSCConfig = VRCOSCConfig()
|
||||
|
||||
@get:JvmName("getVMC")
|
||||
val vmc: VMCConfig = VMCConfig()
|
||||
|
||||
val autoBone: AutoBoneConfig = AutoBoneConfig()
|
||||
|
||||
val keybindings: KeybindingsConfig = KeybindingsConfig()
|
||||
|
||||
val skeleton: SkeletonConfig = SkeletonConfig()
|
||||
|
||||
val legTweaks: LegTweaksConfig = LegTweaksConfig()
|
||||
|
||||
val tapDetection: TapDetectionConfig = TapDetectionConfig()
|
||||
|
||||
val resetsConfig: ResetsConfig = ResetsConfig()
|
||||
|
||||
val stayAlignedConfig = StayAlignedConfig()
|
||||
|
||||
val hidConfig = HIDConfig()
|
||||
|
||||
@JsonDeserialize(using = TrackerConfigMapDeserializer::class)
|
||||
@JsonSerialize(keyUsing = StdKeySerializers.StringKeySerializer::class)
|
||||
private val trackers: MutableMap<String, TrackerConfig> = HashMap()
|
||||
|
||||
@JsonDeserialize(using = BridgeConfigMapDeserializer::class)
|
||||
@JsonSerialize(keyUsing = StdKeySerializers.StringKeySerializer::class)
|
||||
private val bridges: MutableMap<String, BridgeConfig> = HashMap()
|
||||
|
||||
val knownDevices: MutableSet<String> = mutableSetOf()
|
||||
|
||||
val overlay: OverlayConfig = OverlayConfig()
|
||||
|
||||
val trackingChecklist: TrackingChecklistConfig = TrackingChecklistConfig()
|
||||
|
||||
val vrcConfig: VRCConfig = VRCConfig()
|
||||
|
||||
init {
|
||||
// Initialize default settings for OSC Router
|
||||
oscRouter.portIn = 9002
|
||||
oscRouter.portOut = 9000
|
||||
|
||||
// Initialize default settings for VRC OSC
|
||||
vrcOSC.portIn = 9001
|
||||
vrcOSC.portOut = 9000
|
||||
vrcOSC
|
||||
.setOSCTrackerRole(
|
||||
TrackerRole.WAIST,
|
||||
vrcOSC.getOSCTrackerRole(TrackerRole.WAIST, true),
|
||||
)
|
||||
vrcOSC
|
||||
.setOSCTrackerRole(
|
||||
TrackerRole.LEFT_FOOT,
|
||||
vrcOSC.getOSCTrackerRole(TrackerRole.WAIST, true),
|
||||
)
|
||||
vrcOSC
|
||||
.setOSCTrackerRole(
|
||||
TrackerRole.RIGHT_FOOT,
|
||||
vrcOSC.getOSCTrackerRole(TrackerRole.WAIST, true),
|
||||
)
|
||||
|
||||
// Initialize default settings for VMC
|
||||
vmc.portIn = 39540
|
||||
vmc.portOut = 39539
|
||||
}
|
||||
|
||||
fun getTrackers(): Map<String, TrackerConfig> = trackers
|
||||
|
||||
fun getBridges(): Map<String, BridgeConfig> = bridges
|
||||
|
||||
fun hasTrackerByName(name: String): Boolean = trackers.containsKey(name)
|
||||
|
||||
fun getTracker(tracker: Tracker): TrackerConfig {
|
||||
var config = trackers[tracker.name]
|
||||
if (config == null) {
|
||||
config = TrackerConfig(tracker)
|
||||
trackers[tracker.name] = config
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
fun readTrackerConfig(tracker: Tracker) {
|
||||
if (tracker.userEditable) {
|
||||
val config = getTracker(tracker)
|
||||
tracker.readConfig(config)
|
||||
if (tracker.isImu()) tracker.resetsHandler.readDriftCompensationConfig(driftCompensation)
|
||||
tracker.resetsHandler.readResetConfig(resetsConfig)
|
||||
if (tracker.allowReset) {
|
||||
tracker.saveMountingResetOrientation(config)
|
||||
}
|
||||
if (tracker.allowFiltering) {
|
||||
tracker
|
||||
.filteringHandler
|
||||
.readFilteringConfig(filters, tracker.getRotation())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun writeTrackerConfig(tracker: Tracker?) {
|
||||
if (tracker?.userEditable == true) {
|
||||
val tc = getTracker(tracker)
|
||||
tracker.writeConfig(tc)
|
||||
}
|
||||
}
|
||||
|
||||
fun getBridge(bridgeKey: String): BridgeConfig {
|
||||
var config = bridges[bridgeKey]
|
||||
if (config == null) {
|
||||
config = BridgeConfig()
|
||||
bridges[bridgeKey] = config
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
fun isKnownDevice(mac: String?): Boolean = knownDevices.contains(mac)
|
||||
|
||||
fun addKnownDevice(mac: String): Boolean = knownDevices.add(mac)
|
||||
|
||||
fun forgetKnownDevice(mac: String): Boolean = knownDevices.remove(mac)
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package dev.slimevr.config.serializers;
|
||||
|
||||
/**
|
||||
* This class allows the use of the utility super class MapDeserializer that
|
||||
* takes the Value of a map as its Generic parameter. It is so you can use that
|
||||
* class in a @JsonDeserialize annotation on the Map field inside the config
|
||||
* instance
|
||||
*
|
||||
* @see dev.slimevr.config.VRConfig
|
||||
*/
|
||||
public class BooleanMapDeserializer extends MapDeserializer<Boolean> {
|
||||
public BooleanMapDeserializer() {
|
||||
super(Boolean.class);
|
||||
}
|
||||
}
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
package dev.slimevr.config.serializers;
|
||||
|
||||
import dev.slimevr.config.BridgeConfig;
|
||||
|
||||
|
||||
/**
|
||||
* This class allows the use of the utility super class MapDeserializer that
|
||||
* takes the Value of a map as its Generic parameter. It is so you can use that
|
||||
* class in a @JsonDeserialize annotation on the Map field inside the config
|
||||
* instance
|
||||
*
|
||||
* @see dev.slimevr.config.VRConfig
|
||||
*/
|
||||
public class BridgeConfigMapDeserializer extends MapDeserializer<BridgeConfig> {
|
||||
public BridgeConfigMapDeserializer() {
|
||||
super(BridgeConfig.class);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package dev.slimevr.config.serializers;
|
||||
|
||||
/**
|
||||
* This class allows the use of the utility super class MapDeserializer that
|
||||
* takes the Value of a map as its Generic parameter. It is so you can use that
|
||||
* class in a @JsonDeserialize annotation on the Map field inside the config
|
||||
* instance
|
||||
*
|
||||
* @see dev.slimevr.config.VRConfig
|
||||
*/
|
||||
public class FloatMapDeserializer extends MapDeserializer<Float> {
|
||||
public FloatMapDeserializer() {
|
||||
super(Float.class);
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package dev.slimevr.config.serializers;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.type.MapType;
|
||||
import com.fasterxml.jackson.databind.type.TypeFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
|
||||
/**
|
||||
* This class is a utility class that allows to write Map serializers easily to
|
||||
* be used in the VRConfig (@see {@link dev.slimevr.config.VRConfig})
|
||||
*
|
||||
* @see BooleanMapDeserializer to see how it is used
|
||||
*/
|
||||
public abstract class MapDeserializer<T> extends JsonDeserializer<HashMap<String, T>> {
|
||||
|
||||
private final Class<T> valueClass;
|
||||
|
||||
public MapDeserializer(Class<T> valueClass) {
|
||||
super();
|
||||
this.valueClass = valueClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, T> deserialize(JsonParser p, DeserializationContext dc)
|
||||
throws IOException {
|
||||
TypeFactory typeFactory = dc.getTypeFactory();
|
||||
MapType mapType = typeFactory
|
||||
.constructMapType(HashMap.class, String.class, valueClass);
|
||||
return dc.readValue(p, mapType);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package dev.slimevr.config.serializers;
|
||||
|
||||
import com.fasterxml.jackson.core.JacksonException;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.github.axisangles.ktmath.ObjectQuaternion;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class QuaternionDeserializer extends JsonDeserializer<ObjectQuaternion> {
|
||||
@Override
|
||||
public ObjectQuaternion deserialize(JsonParser p, DeserializationContext ctxt)
|
||||
throws IOException, JacksonException {
|
||||
JsonNode node = p.getCodec().readTree(p);
|
||||
|
||||
return new ObjectQuaternion(
|
||||
(float) node.get("w").asDouble(),
|
||||
(float) node.get("x").asDouble(),
|
||||
(float) node.get("y").asDouble(),
|
||||
(float) node.get("z").asDouble()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package dev.slimevr.config.serializers;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import io.github.axisangles.ktmath.ObjectQuaternion;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class QuaternionSerializer extends JsonSerializer<ObjectQuaternion> {
|
||||
|
||||
@Override
|
||||
public void serialize(ObjectQuaternion value, JsonGenerator gen, SerializerProvider serializers)
|
||||
throws IOException {
|
||||
gen.writeStartObject();
|
||||
gen.writeNumberField("x", value.getX());
|
||||
gen.writeNumberField("y", value.getY());
|
||||
gen.writeNumberField("z", value.getZ());
|
||||
gen.writeNumberField("w", value.getW());
|
||||
gen.writeEndObject();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package dev.slimevr.config.serializers
|
||||
|
||||
import io.github.axisangles.ktmath.ObjectQuaternion
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
|
||||
object QuaternionSerializer : KSerializer<ObjectQuaternion> {
|
||||
@Serializable
|
||||
private data class QuaternionSurrogate(val x: Float, val y: Float, val z: Float, val w: Float)
|
||||
|
||||
override val descriptor: SerialDescriptor = QuaternionSurrogate.serializer().descriptor
|
||||
|
||||
override fun serialize(encoder: Encoder, value: ObjectQuaternion) {
|
||||
val surrogate = QuaternionSurrogate(value.x, value.y, value.z, value.w)
|
||||
encoder.encodeSerializableValue(QuaternionSurrogate.serializer(), surrogate)
|
||||
}
|
||||
|
||||
override fun deserialize(decoder: Decoder): ObjectQuaternion {
|
||||
val surrogate = decoder.decodeSerializableValue(QuaternionSurrogate.serializer())
|
||||
return ObjectQuaternion(surrogate.x, surrogate.y, surrogate.z, surrogate.w)
|
||||
}
|
||||
}
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
package dev.slimevr.config.serializers;
|
||||
|
||||
import dev.slimevr.config.TrackerConfig;
|
||||
|
||||
|
||||
/**
|
||||
* This class allows the use of the utility super class MapDeserializer that
|
||||
* takes the Value of a map as its Generic parameter. It is so you can use that
|
||||
* class in a @JsonDeserialize annotation on the Map field inside the config
|
||||
* instance
|
||||
*
|
||||
* @see dev.slimevr.config.VRConfig
|
||||
*/
|
||||
public class TrackerConfigMapDeserializer extends MapDeserializer<TrackerConfig> {
|
||||
public TrackerConfigMapDeserializer() {
|
||||
super(TrackerConfig.class);
|
||||
}
|
||||
}
|
||||
@@ -106,6 +106,8 @@ class VRChatConfigManager(val server: VRServer, private val handler: VRCConfigHa
|
||||
private val listeners: MutableList<VRCConfigListener> = CopyOnWriteArrayList()
|
||||
var currentValues: VRCConfigValues? = null
|
||||
var currentValidity: VRCConfigValidity? = null
|
||||
val mutedWarnings
|
||||
get() = server.configManager.settings.get().vrcConfig.mutedWarnings
|
||||
|
||||
val isSupported: Boolean
|
||||
get() = handler.isSupported
|
||||
@@ -118,13 +120,19 @@ class VRChatConfigManager(val server: VRServer, private val handler: VRCConfigHa
|
||||
val keys = VRCConfigValidity::class.java.declaredFields.asSequence().map { p -> p.name }
|
||||
if (!keys.contains(key)) return
|
||||
|
||||
if (!server.configManager.vrConfig.vrcConfig.mutedWarnings.contains(key)) {
|
||||
server.configManager.vrConfig.vrcConfig.mutedWarnings.add(key)
|
||||
} else {
|
||||
server.configManager.vrConfig.vrcConfig.mutedWarnings.remove(key)
|
||||
}
|
||||
server.configManager.settings.updateAndSave {
|
||||
if (!mutedWarnings.contains(key)) {
|
||||
mutedWarnings.add(key)
|
||||
} else {
|
||||
mutedWarnings.remove(key)
|
||||
}
|
||||
|
||||
server.configManager.saveConfig()
|
||||
it.copy(
|
||||
vrcConfig = it.vrcConfig.copy(
|
||||
mutedWarnings = mutedWarnings
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
val recommended = recommendedValues()
|
||||
val validity = currentValidity ?: return
|
||||
@@ -134,7 +142,7 @@ class VRChatConfigManager(val server: VRServer, private val handler: VRCConfigHa
|
||||
validity,
|
||||
values,
|
||||
recommended,
|
||||
server.configManager.vrConfig.vrcConfig.mutedWarnings,
|
||||
mutedWarnings,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -179,7 +187,7 @@ class VRChatConfigManager(val server: VRServer, private val handler: VRCConfigHa
|
||||
val values = currentValues ?: return
|
||||
val recommended = recommendedValues()
|
||||
val validity = checkValidity(values, recommended)
|
||||
listener.onChange(validity, values, recommended, server.configManager.vrConfig.vrcConfig.mutedWarnings)
|
||||
listener.onChange(validity, values, recommended, mutedWarnings)
|
||||
}
|
||||
|
||||
fun removeListener(listener: VRCConfigListener) {
|
||||
@@ -211,7 +219,7 @@ class VRChatConfigManager(val server: VRServer, private val handler: VRCConfigHa
|
||||
currentValidity = validity
|
||||
currentValues = values
|
||||
listeners.forEach {
|
||||
it.onChange(validity, values, recommended, server.configManager.vrConfig.vrcConfig.mutedWarnings)
|
||||
it.onChange(validity, values, recommended, mutedWarnings)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,9 @@ import com.illposed.osc.*;
|
||||
import com.illposed.osc.messageselector.OSCPatternAddressMessageSelector;
|
||||
import com.illposed.osc.transport.OSCPortIn;
|
||||
import com.illposed.osc.transport.OSCPortOut;
|
||||
import dev.slimevr.config.ConfigFileHandler;
|
||||
import dev.slimevr.config.OSCConfig;
|
||||
import dev.slimevr.config.SettingsConfig;
|
||||
import io.eiren.util.collections.FastList;
|
||||
import io.eiren.util.logging.LogManager;
|
||||
|
||||
@@ -17,7 +19,7 @@ import java.net.UnknownHostException;
|
||||
public class OSCRouter {
|
||||
private OSCPortIn oscReceiver;
|
||||
private OSCPortOut oscSender;
|
||||
private final OSCConfig config;
|
||||
private final ConfigFileHandler<SettingsConfig> settings;
|
||||
private final FastList<OSCHandler> oscHandlers;
|
||||
private int lastPortIn;
|
||||
private int lastPortOut;
|
||||
@@ -25,16 +27,18 @@ public class OSCRouter {
|
||||
private long timeAtLastError;
|
||||
|
||||
public OSCRouter(
|
||||
OSCConfig oscConfig,
|
||||
ConfigFileHandler<SettingsConfig> settings,
|
||||
FastList<OSCHandler> oscHandlers
|
||||
) {
|
||||
this.config = oscConfig;
|
||||
this.settings = settings;
|
||||
this.oscHandlers = oscHandlers;
|
||||
|
||||
refreshSettings(false);
|
||||
}
|
||||
|
||||
public void refreshSettings(boolean refreshHandlersSettings) {
|
||||
OSCConfig config = settings.get().getOscRouter();
|
||||
|
||||
if (refreshHandlersSettings) {
|
||||
for (OSCHandler oscHandler : oscHandlers) {
|
||||
oscHandler.refreshSettings(false);
|
||||
|
||||
@@ -41,7 +41,6 @@ import java.net.InetSocketAddress
|
||||
class VMCHandler(
|
||||
private val server: VRServer,
|
||||
private val humanPoseManager: HumanPoseManager,
|
||||
private val config: VMCConfig,
|
||||
) : OSCHandler {
|
||||
private var oscReceiver: OSCPortIn? = null
|
||||
private var oscSender: OSCPortOut? = null
|
||||
@@ -67,6 +66,9 @@ class VMCHandler(
|
||||
}
|
||||
|
||||
override fun refreshSettings(refreshRouterSettings: Boolean) {
|
||||
val settings = server.configManager.settings.get()
|
||||
val config = settings.vmc
|
||||
|
||||
anchorHip = config.anchorHip
|
||||
mirrorTracking = config.mirrorTracking
|
||||
|
||||
@@ -117,6 +119,8 @@ class VMCHandler(
|
||||
}
|
||||
|
||||
override fun updateOscReceiver(portIn: Int, args: Array<String>) {
|
||||
val settings = server.configManager.settings.get()
|
||||
val config = settings.vmc
|
||||
// Stops listening and closes OSC port
|
||||
val wasListening = oscReceiver != null && oscReceiver!!.isListening
|
||||
if (wasListening) {
|
||||
@@ -154,6 +158,9 @@ class VMCHandler(
|
||||
}
|
||||
|
||||
override fun updateOscSender(portOut: Int, ip: String) {
|
||||
val settings = server.configManager.settings.get()
|
||||
val config = settings.vmc
|
||||
|
||||
// Stop sending
|
||||
val wasConnected = oscSender != null && oscSender!!.isConnected
|
||||
if (wasConnected) {
|
||||
|
||||
@@ -11,11 +11,11 @@ import com.illposed.osc.transport.OSCPortOut
|
||||
import com.jme3.math.FastMath
|
||||
import com.jme3.system.NanoTimer
|
||||
import dev.slimevr.VRServer
|
||||
import dev.slimevr.config.VRCOSCConfig
|
||||
import dev.slimevr.protocol.rpc.setup.RPCUtil
|
||||
import dev.slimevr.tracking.trackers.Device
|
||||
import dev.slimevr.tracking.trackers.Tracker
|
||||
import dev.slimevr.tracking.trackers.TrackerPosition
|
||||
import dev.slimevr.tracking.trackers.TrackerRole
|
||||
import dev.slimevr.tracking.trackers.TrackerStatus
|
||||
import io.eiren.util.collections.FastList
|
||||
import io.eiren.util.logging.LogManager
|
||||
@@ -26,6 +26,7 @@ import io.github.axisangles.ktmath.Vector3
|
||||
import java.io.IOException
|
||||
import java.net.InetAddress
|
||||
import java.net.InetSocketAddress
|
||||
import java.util.Locale
|
||||
|
||||
private const val OFFSET_SLERP_FACTOR = 0.5f // Guessed from eyeing VRChat
|
||||
|
||||
@@ -34,7 +35,6 @@ private const val OFFSET_SLERP_FACTOR = 0.5f // Guessed from eyeing VRChat
|
||||
*/
|
||||
class VRCOSCHandler(
|
||||
private val server: VRServer,
|
||||
private val config: VRCOSCConfig,
|
||||
private val computedTrackers: List<Tracker>,
|
||||
) : OSCHandler {
|
||||
private val localIp = RPCUtil.getLocalIp()
|
||||
@@ -73,16 +73,35 @@ class VRCOSCHandler(
|
||||
private var fpsTimer: NanoTimer? = null
|
||||
private var vrcOscQueryHandler: VRCOSCQueryHandler? = null
|
||||
|
||||
private val configTrackers
|
||||
get() = server.configManager.settings.get().vrcOSC.trackers
|
||||
|
||||
init {
|
||||
refreshSettings(false)
|
||||
}
|
||||
|
||||
fun getOSCTrackerRole(role: TrackerRole, def: Boolean): Boolean = configTrackers.getOrDefault(role.name.lowercase(
|
||||
Locale.getDefault()), def)
|
||||
|
||||
fun setOSCTrackerRole(role: TrackerRole, value: Boolean) {
|
||||
server.configManager.settings.update {
|
||||
configTrackers[role.name.lowercase(Locale.getDefault())] = value;
|
||||
it.copy(
|
||||
vrcOSC = it.vrcOSC.copy(
|
||||
trackers = configTrackers
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun refreshSettings(refreshRouterSettings: Boolean) {
|
||||
val settings = server.configManager.settings.get()
|
||||
val config = settings.vrcOSC
|
||||
// Sets which trackers are enabled and force head and hands to false
|
||||
for (i in computedTrackers.indices) {
|
||||
if (computedTrackers[i].trackerPosition != TrackerPosition.HEAD || computedTrackers[i].trackerPosition != TrackerPosition.LEFT_HAND || computedTrackers[i].trackerPosition != TrackerPosition.RIGHT_HAND) {
|
||||
trackersEnabled[i] = config
|
||||
.getOSCTrackerRole(
|
||||
// FIXME: possible data race? if the settings are getting refreshed at the same time the config profile gets changed
|
||||
trackersEnabled[i] = getOSCTrackerRole(
|
||||
computedTrackers[i].trackerPosition!!.trackerRole!!,
|
||||
false,
|
||||
)
|
||||
@@ -145,6 +164,9 @@ class VRCOSCHandler(
|
||||
}
|
||||
|
||||
override fun updateOscReceiver(portIn: Int, args: Array<String>) {
|
||||
val settings = server.configManager.settings.get()
|
||||
val config = settings.vrcOSC
|
||||
|
||||
// Stop listening
|
||||
val wasListening = oscReceiver != null && oscReceiver!!.isListening
|
||||
if (wasListening) {
|
||||
@@ -184,6 +206,9 @@ class VRCOSCHandler(
|
||||
}
|
||||
|
||||
override fun updateOscSender(portOut: Int, ip: String) {
|
||||
val settings = server.configManager.settings.get()
|
||||
val config = settings.vrcOSC
|
||||
|
||||
// Stop sending
|
||||
val wasConnected = oscSender != null && oscSender!!.isConnected
|
||||
if (wasConnected) {
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package dev.slimevr.protocol.rpc
|
||||
|
||||
import com.google.flatbuffers.FlatBufferBuilder
|
||||
import dev.slimevr.config.MountingMethods
|
||||
import dev.slimevr.config.config
|
||||
import dev.slimevr.config.MountingMethod
|
||||
import dev.slimevr.protocol.GenericConnection
|
||||
import dev.slimevr.protocol.ProtocolAPI
|
||||
import dev.slimevr.protocol.ProtocolHandler
|
||||
@@ -170,7 +169,7 @@ class RPCHandler(private val api: ProtocolAPI) : ProtocolHandler<RpcMessageHeade
|
||||
messageHeader: RpcMessageHeader,
|
||||
) {
|
||||
val fbb = FlatBufferBuilder(32)
|
||||
val config = api.server.configManager.vrConfig.overlay
|
||||
val config = api.server.configManager.settings.get().overlay
|
||||
val response = OverlayDisplayModeResponse
|
||||
.createOverlayDisplayModeResponse(fbb, config.isVisible, config.isMirrored)
|
||||
val outbound = this.createRPCMessage(fbb, RpcMessage.OverlayDisplayModeResponse, response, messageHeader)
|
||||
@@ -184,11 +183,14 @@ class RPCHandler(private val api: ProtocolAPI) : ProtocolHandler<RpcMessageHeade
|
||||
) {
|
||||
val req = messageHeader
|
||||
.message(OverlayDisplayModeChangeRequest()) as? OverlayDisplayModeChangeRequest ?: return
|
||||
val config = api.server.configManager.vrConfig.overlay
|
||||
config.isMirrored = req.isMirrored
|
||||
config.isVisible = req.isVisible
|
||||
|
||||
api.server.configManager.saveConfig()
|
||||
api.server.configManager.settings.updateAndSave {
|
||||
it.copy(
|
||||
overlay = it.overlay.copy(
|
||||
isMirrored = req.isMirrored,
|
||||
isVisible = req.isVisible,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun onSkeletonResetAllRequest(conn: GenericConnection, messageHeader: RpcMessageHeader) {
|
||||
@@ -303,8 +305,11 @@ class RPCHandler(private val api: ProtocolAPI) : ProtocolHandler<RpcMessageHeade
|
||||
req.mountingOrientation().y(),
|
||||
req.mountingOrientation().z(),
|
||||
)
|
||||
api.server.configManager.vrConfig.resetsConfig.lastMountingMethod =
|
||||
MountingMethods.MANUAL
|
||||
api.server.configManager.settings.updateAndSave {
|
||||
it.copy(resetsConfig = it.resetsConfig.copy(
|
||||
lastMountingMethod = MountingMethod.MANUAL
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -452,7 +457,7 @@ class RPCHandler(private val api: ProtocolAPI) : ProtocolHandler<RpcMessageHeade
|
||||
val response = MagToggleResponse.createMagToggleResponse(
|
||||
fbb,
|
||||
0,
|
||||
api.server.configManager.vrConfig.server.useMagnetometerOnAllTrackers,
|
||||
api.server.configManager.settings.get().server.useMagnetometerOnAllTrackers,
|
||||
)
|
||||
fbb.finish(createRPCMessage(fbb, RpcMessage.MagToggleResponse, response, messageHeader))
|
||||
conn.send(fbb.dataBuffer())
|
||||
@@ -532,16 +537,15 @@ class RPCHandler(private val api: ProtocolAPI) : ProtocolHandler<RpcMessageHeade
|
||||
messageHeader.message(EnableStayAlignedRequest()) as? EnableStayAlignedRequest
|
||||
?: return
|
||||
|
||||
val configManager = api.server.configManager
|
||||
|
||||
val config = configManager.vrConfig.stayAlignedConfig
|
||||
config.enabled = request.enable()
|
||||
if (request.enable()) {
|
||||
config.setupComplete = true
|
||||
api.server.configManager.settings.updateAndSave {
|
||||
it.copy(
|
||||
stayAlignedConfig = it.stayAlignedConfig.copy(
|
||||
enabled = request.enable(),
|
||||
setupComplete = if (request.enable()) true else it.stayAlignedConfig.setupComplete,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
configManager.saveConfig()
|
||||
|
||||
sendSettingsChangedResponse(conn, messageHeader)
|
||||
}
|
||||
|
||||
@@ -551,28 +555,46 @@ class RPCHandler(private val api: ProtocolAPI) : ProtocolHandler<RpcMessageHeade
|
||||
?: return
|
||||
|
||||
val configManager = api.server.configManager
|
||||
val config = configManager.vrConfig.stayAlignedConfig
|
||||
|
||||
val pose = request.pose()
|
||||
configManager.settings.updateAndSave {
|
||||
val relaxedPose = RelaxedPose.fromTrackers(api.server.humanPoseManager.skeleton)
|
||||
val pose = request.pose()
|
||||
|
||||
val poseConfig =
|
||||
when (pose) {
|
||||
StayAlignedRelaxedPose.STANDING -> config.standingRelaxedPose
|
||||
StayAlignedRelaxedPose.SITTING -> config.sittingRelaxedPose
|
||||
StayAlignedRelaxedPose.FLAT -> config.flatRelaxedPose
|
||||
else -> return
|
||||
}
|
||||
LogManager.info("[detectStayAlignedRelaxedPose] pose=$pose $relaxedPose")
|
||||
|
||||
val relaxedPose = RelaxedPose.fromTrackers(api.server.humanPoseManager.skeleton)
|
||||
it.copy(
|
||||
stayAlignedConfig = when (pose) {
|
||||
StayAlignedRelaxedPose.STANDING -> it.stayAlignedConfig.copy(
|
||||
standingRelaxedPose = it.stayAlignedConfig.standingRelaxedPose.copy(
|
||||
enabled = true,
|
||||
upperLegAngleInDeg = relaxedPose.upperLeg.toDeg(),
|
||||
lowerLegAngleInDeg = relaxedPose.lowerLeg.toDeg(),
|
||||
footAngleInDeg = relaxedPose.foot.toDeg(),
|
||||
),
|
||||
)
|
||||
|
||||
poseConfig.enabled = true
|
||||
poseConfig.upperLegAngleInDeg = relaxedPose.upperLeg.toDeg()
|
||||
poseConfig.lowerLegAngleInDeg = relaxedPose.lowerLeg.toDeg()
|
||||
poseConfig.footAngleInDeg = relaxedPose.foot.toDeg()
|
||||
StayAlignedRelaxedPose.SITTING -> it.stayAlignedConfig.copy(
|
||||
sittingRelaxedPose = it.stayAlignedConfig.sittingRelaxedPose.copy(
|
||||
enabled = true,
|
||||
upperLegAngleInDeg = relaxedPose.upperLeg.toDeg(),
|
||||
lowerLegAngleInDeg = relaxedPose.lowerLeg.toDeg(),
|
||||
footAngleInDeg = relaxedPose.foot.toDeg(),
|
||||
),
|
||||
)
|
||||
|
||||
configManager.saveConfig()
|
||||
StayAlignedRelaxedPose.FLAT -> it.stayAlignedConfig.copy(
|
||||
flatRelaxedPose = it.stayAlignedConfig.flatRelaxedPose.copy(
|
||||
enabled = true,
|
||||
upperLegAngleInDeg = relaxedPose.upperLeg.toDeg(),
|
||||
lowerLegAngleInDeg = relaxedPose.lowerLeg.toDeg(),
|
||||
footAngleInDeg = relaxedPose.foot.toDeg(),
|
||||
),
|
||||
)
|
||||
|
||||
LogManager.info("[detectStayAlignedRelaxedPose] pose=$pose $relaxedPose")
|
||||
else -> error("unknown pose")
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
sendSettingsChangedResponse(conn, messageHeader)
|
||||
}
|
||||
@@ -583,24 +605,45 @@ class RPCHandler(private val api: ProtocolAPI) : ProtocolHandler<RpcMessageHeade
|
||||
?: return
|
||||
|
||||
val configManager = api.server.configManager
|
||||
val config = configManager.vrConfig.stayAlignedConfig
|
||||
configManager.settings.updateAndSave {
|
||||
val relaxedPose =
|
||||
RelaxedPose.fromTrackers(api.server.humanPoseManager.skeleton)
|
||||
val pose = request.pose()
|
||||
|
||||
val pose = request.pose()
|
||||
LogManager.info("[detectStayAlignedRelaxedPose] pose=$pose $relaxedPose")
|
||||
it.copy(
|
||||
stayAlignedConfig = when (pose) {
|
||||
StayAlignedRelaxedPose.STANDING -> it.stayAlignedConfig.copy(
|
||||
standingRelaxedPose = it.stayAlignedConfig.standingRelaxedPose.copy(
|
||||
enabled = false,
|
||||
upperLegAngleInDeg = 0f,
|
||||
lowerLegAngleInDeg = 0f,
|
||||
footAngleInDeg = 0f,
|
||||
),
|
||||
)
|
||||
|
||||
val poseConfig =
|
||||
when (pose) {
|
||||
StayAlignedRelaxedPose.STANDING -> config.standingRelaxedPose
|
||||
StayAlignedRelaxedPose.SITTING -> config.sittingRelaxedPose
|
||||
StayAlignedRelaxedPose.FLAT -> config.flatRelaxedPose
|
||||
else -> return
|
||||
}
|
||||
StayAlignedRelaxedPose.SITTING -> it.stayAlignedConfig.copy(
|
||||
sittingRelaxedPose = it.stayAlignedConfig.sittingRelaxedPose.copy(
|
||||
enabled = false,
|
||||
upperLegAngleInDeg = 0f,
|
||||
lowerLegAngleInDeg = 0f,
|
||||
footAngleInDeg = 0f,
|
||||
),
|
||||
)
|
||||
|
||||
poseConfig.enabled = false
|
||||
poseConfig.upperLegAngleInDeg = 0.0f
|
||||
poseConfig.lowerLegAngleInDeg = 0.0f
|
||||
poseConfig.footAngleInDeg = 0.0f
|
||||
StayAlignedRelaxedPose.FLAT -> it.stayAlignedConfig.copy(
|
||||
flatRelaxedPose = it.stayAlignedConfig.flatRelaxedPose.copy(
|
||||
enabled = false,
|
||||
upperLegAngleInDeg = 0f,
|
||||
lowerLegAngleInDeg = 0f,
|
||||
footAngleInDeg = 0f,
|
||||
),
|
||||
)
|
||||
|
||||
LogManager.info("[resetStayAlignedRelaxedPose] pose=$pose")
|
||||
else -> error("unknown pose")
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
sendSettingsChangedResponse(conn, messageHeader)
|
||||
}
|
||||
|
||||
@@ -29,15 +29,15 @@ class RPCVRChatHandler(
|
||||
val values = configManager.currentValues
|
||||
val recommended = configManager.recommendedValues()
|
||||
// FUCKING KOTLIN BRING ME BACK MY FUCKING TERNARY OPERATORS!!!!!!!!!!!!!!!!! - With love <3 Futura
|
||||
val validity = if (values !== null) configManager.checkValidity(values, recommended) else null
|
||||
val validity = if (values != null) configManager.checkValidity(values, recommended) else null
|
||||
|
||||
val response = buildVRCConfigStateResponse(
|
||||
fbb,
|
||||
isSupported = api.server.vrcConfigManager.isSupported,
|
||||
isSupported = configManager.isSupported,
|
||||
validity = validity,
|
||||
values = values,
|
||||
recommended = api.server.vrcConfigManager.recommendedValues(),
|
||||
muted = api.server.configManager.vrConfig.vrcConfig.mutedWarnings,
|
||||
recommended = configManager.recommendedValues(),
|
||||
muted = configManager.mutedWarnings,
|
||||
)
|
||||
|
||||
val outbound = rpcHandler.createRPCMessage(
|
||||
@@ -50,8 +50,7 @@ class RPCVRChatHandler(
|
||||
}
|
||||
|
||||
private fun onToggleMuteRequest(conn: GenericConnection, messageHeader: RpcMessageHeader) {
|
||||
val req = messageHeader.message(VRCConfigSettingToggleMute()) as VRCConfigSettingToggleMute?
|
||||
?: return
|
||||
val req = messageHeader.message(VRCConfigSettingToggleMute()) as VRCConfigSettingToggleMute
|
||||
api.server.vrcConfigManager.toggleMuteWarning(req.key())
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ import solarxr_protocol.rpc.RpcMessageHeader
|
||||
import java.util.function.Consumer
|
||||
|
||||
class RPCResetHandler(var rpcHandler: RPCHandler, var api: ProtocolAPI) : ResetListener {
|
||||
val resetsConfig = api.server.configManager.vrConfig.resetsConfig
|
||||
|
||||
init {
|
||||
this.api.server.resetHandler.addListener(this)
|
||||
@@ -38,6 +37,8 @@ class RPCResetHandler(var rpcHandler: RPCHandler, var api: ProtocolAPI) : ResetL
|
||||
}
|
||||
}
|
||||
|
||||
val resetsConfig = api.server.configManager.settings.get().resetsConfig
|
||||
|
||||
if (req.resetType() == ResetType.Yaw) {
|
||||
if (bodyParts.isEmpty()) {
|
||||
api.server.scheduleResetTrackersYaw(RESET_SOURCE_NAME, (resetsConfig.yawResetDelay * 1000).toLong())
|
||||
@@ -108,7 +109,7 @@ class RPCResetHandler(var rpcHandler: RPCHandler, var api: ProtocolAPI) : ResetL
|
||||
|
||||
fun forAllListeners(action: Consumer<in GenericConnection?>?) {
|
||||
this.api
|
||||
.getAPIServers()
|
||||
.apiServers
|
||||
.forEach(
|
||||
Consumer { server: ProtocolAPIServer? ->
|
||||
server!!
|
||||
|
||||
+4
-22
@@ -113,20 +113,6 @@ public class RPCSettingsBuilder {
|
||||
);
|
||||
}
|
||||
|
||||
public static int createDriftCompensationSettings(
|
||||
FlatBufferBuilder fbb,
|
||||
DriftCompensationConfig driftCompensationConfig
|
||||
) {
|
||||
return DriftCompensationSettings
|
||||
.createDriftCompensationSettings(
|
||||
fbb,
|
||||
driftCompensationConfig.getEnabled(),
|
||||
driftCompensationConfig.getPrediction(),
|
||||
driftCompensationConfig.getAmount(),
|
||||
driftCompensationConfig.getMaxResets()
|
||||
);
|
||||
}
|
||||
|
||||
public static int createTapDetectionSettings(
|
||||
FlatBufferBuilder fbb,
|
||||
TapDetectionConfig tapDetectionConfig
|
||||
@@ -212,8 +198,8 @@ public class RPCSettingsBuilder {
|
||||
int skeletonConfigOffset = SkeletonHeight
|
||||
.createSkeletonHeight(
|
||||
fbb,
|
||||
skeletonConfig.getHmdHeight(),
|
||||
skeletonConfig.getFloorHeight()
|
||||
skeletonConfig.hmdHeight,
|
||||
skeletonConfig.floorHeight
|
||||
);
|
||||
return ModelSettings
|
||||
.createModelSettings(
|
||||
@@ -366,11 +352,7 @@ public class RPCSettingsBuilder {
|
||||
fbb,
|
||||
server.configManager.getVrConfig().getFilters()
|
||||
),
|
||||
RPCSettingsBuilder
|
||||
.createDriftCompensationSettings(
|
||||
fbb,
|
||||
server.configManager.getVrConfig().getDriftCompensation()
|
||||
),
|
||||
0,
|
||||
RPCSettingsBuilder
|
||||
.createOSCRouterSettings(
|
||||
fbb,
|
||||
@@ -384,7 +366,7 @@ public class RPCSettingsBuilder {
|
||||
RPCSettingsBuilder
|
||||
.createVMCOSCSettings(
|
||||
fbb,
|
||||
server.configManager.getVrConfig().getVMC()
|
||||
server.configManager.getVrConfig().getVmc()
|
||||
),
|
||||
RPCSettingsBuilder
|
||||
.createModelSettings(
|
||||
|
||||
+154
-149
@@ -2,7 +2,12 @@ package dev.slimevr.protocol.rpc.settings
|
||||
|
||||
import com.google.flatbuffers.FlatBufferBuilder
|
||||
import dev.slimevr.bridge.ISteamVRBridge
|
||||
import dev.slimevr.config.ArmsResetModes
|
||||
import dev.slimevr.config.ArmsResetMode
|
||||
import dev.slimevr.config.OSCConfig
|
||||
import dev.slimevr.config.ResetsConfig
|
||||
import dev.slimevr.config.TapDetectionConfig
|
||||
import dev.slimevr.config.VMCConfig
|
||||
import dev.slimevr.config.VRCOSCConfig
|
||||
import dev.slimevr.filtering.TrackerFilters
|
||||
import dev.slimevr.protocol.GenericConnection
|
||||
import dev.slimevr.protocol.ProtocolAPI
|
||||
@@ -10,6 +15,7 @@ import dev.slimevr.protocol.rpc.RPCHandler
|
||||
import dev.slimevr.tracking.processor.config.SkeletonConfigToggles
|
||||
import dev.slimevr.tracking.processor.config.SkeletonConfigValues
|
||||
import dev.slimevr.tracking.trackers.TrackerRole
|
||||
import dev.slimevr.tracking.trackers.toKey
|
||||
import solarxr_protocol.rpc.ChangeSettingsRequest
|
||||
import solarxr_protocol.rpc.RpcMessage
|
||||
import solarxr_protocol.rpc.RpcMessageHeader
|
||||
@@ -68,143 +74,120 @@ class RPCSettingsHandler(var rpcHandler: RPCHandler, var api: ProtocolAPI) {
|
||||
if (req.filtering() != null) {
|
||||
val type = TrackerFilters.fromId(req.filtering().type())
|
||||
if (type != null) {
|
||||
val filtersConfig = api.server.configManager
|
||||
.vrConfig
|
||||
.filters
|
||||
filtersConfig.type = type.configKey
|
||||
filtersConfig.amount = req.filtering().amount()
|
||||
filtersConfig.updateTrackersFilters()
|
||||
api.server.configManager.settings.update {
|
||||
it.copy(
|
||||
filters = it.filters.copy(
|
||||
type = type.configKey,
|
||||
amount = req.filtering().amount(),
|
||||
),
|
||||
)
|
||||
}
|
||||
filtersConfig.updateTrackersFilters() // FIXME: move this outside of the config file
|
||||
}
|
||||
}
|
||||
|
||||
if (req.driftCompensation() != null) {
|
||||
val driftCompensationConfig = api.server.configManager
|
||||
.vrConfig
|
||||
.driftCompensation
|
||||
driftCompensationConfig.enabled = req.driftCompensation().enabled()
|
||||
driftCompensationConfig.prediction = req.driftCompensation().prediction()
|
||||
driftCompensationConfig.amount = req.driftCompensation().amount()
|
||||
driftCompensationConfig.maxResets = req.driftCompensation().maxResets()
|
||||
driftCompensationConfig.updateTrackersDriftCompensation()
|
||||
}
|
||||
|
||||
if (req.oscRouter() != null) {
|
||||
val oscRouterConfig = api.server.configManager
|
||||
.vrConfig
|
||||
.oscRouter
|
||||
val oscRouter = api.server.oSCRouter
|
||||
val osc = req.oscRouter().oscSettings()
|
||||
if (osc != null) {
|
||||
oscRouterConfig.enabled = osc.enabled()
|
||||
oscRouterConfig.portIn = osc.portIn()
|
||||
oscRouterConfig.portOut = osc.portOut()
|
||||
oscRouterConfig.address = osc.address()
|
||||
api.server.configManager.settings.update {
|
||||
it.copy(
|
||||
oscRouter = if (osc != null) {
|
||||
OSCConfig(
|
||||
enabled = osc.enabled(),
|
||||
portIn = osc.portIn(),
|
||||
portOut = osc.portOut(),
|
||||
address = osc.address(),
|
||||
)
|
||||
} else {
|
||||
it.oscRouter
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
oscRouter.refreshSettings(true)
|
||||
}
|
||||
|
||||
if (req.vrcOsc() != null) {
|
||||
val vrcOSCConfig = api.server.configManager
|
||||
.vrConfig
|
||||
.vrcOSC
|
||||
val vrcOscHandler = api.server.vrcOSCHandler
|
||||
val osc = req.vrcOsc().oscSettings()
|
||||
val trackers = req.vrcOsc().trackers()
|
||||
|
||||
if (osc != null) {
|
||||
vrcOSCConfig.enabled = osc.enabled()
|
||||
vrcOSCConfig.portIn = osc.portIn()
|
||||
vrcOSCConfig.portOut = osc.portOut()
|
||||
vrcOSCConfig.address = osc.address()
|
||||
api.server.configManager.settings.update {
|
||||
it.copy(
|
||||
vrcOSC = if (osc != null) {
|
||||
VRCOSCConfig(
|
||||
enabled = osc.enabled(),
|
||||
portIn = osc.portIn(),
|
||||
portOut = osc.portOut(),
|
||||
address = osc.address(),
|
||||
oscqueryEnabled = req.vrcOsc().oscqueryEnabled(),
|
||||
trackers = if (trackers != null) {
|
||||
mutableMapOf(
|
||||
TrackerRole.HEAD.toKey to trackers.head(),
|
||||
TrackerRole.CHEST.toKey to trackers.chest(),
|
||||
TrackerRole.WAIST.toKey to trackers.waist(),
|
||||
TrackerRole.LEFT_KNEE.toKey to trackers.knees(),
|
||||
TrackerRole.RIGHT_KNEE.toKey to trackers.knees(),
|
||||
TrackerRole.LEFT_FOOT.toKey to trackers.feet(),
|
||||
TrackerRole.RIGHT_FOOT.toKey to trackers.feet(),
|
||||
TrackerRole.LEFT_ELBOW.toKey to trackers.elbows(),
|
||||
TrackerRole.RIGHT_ELBOW.toKey to trackers.elbows(),
|
||||
TrackerRole.LEFT_HAND.toKey to trackers.hands(),
|
||||
TrackerRole.RIGHT_HAND.toKey to trackers.hands(),
|
||||
)
|
||||
} else {
|
||||
it.vrcOSC.trackers
|
||||
},
|
||||
)
|
||||
} else {
|
||||
it.vrcOSC
|
||||
},
|
||||
)
|
||||
}
|
||||
if (trackers != null) {
|
||||
vrcOSCConfig.setOSCTrackerRole(TrackerRole.HEAD, trackers.head())
|
||||
vrcOSCConfig.setOSCTrackerRole(TrackerRole.CHEST, trackers.chest())
|
||||
vrcOSCConfig.setOSCTrackerRole(TrackerRole.WAIST, trackers.waist())
|
||||
vrcOSCConfig.setOSCTrackerRole(TrackerRole.LEFT_KNEE, trackers.knees())
|
||||
vrcOSCConfig.setOSCTrackerRole(TrackerRole.RIGHT_KNEE, trackers.knees())
|
||||
vrcOSCConfig.setOSCTrackerRole(TrackerRole.LEFT_FOOT, trackers.feet())
|
||||
vrcOSCConfig.setOSCTrackerRole(TrackerRole.RIGHT_FOOT, trackers.feet())
|
||||
vrcOSCConfig.setOSCTrackerRole(TrackerRole.LEFT_ELBOW, trackers.elbows())
|
||||
vrcOSCConfig.setOSCTrackerRole(TrackerRole.RIGHT_ELBOW, trackers.elbows())
|
||||
vrcOSCConfig.setOSCTrackerRole(TrackerRole.LEFT_HAND, trackers.hands())
|
||||
vrcOSCConfig.setOSCTrackerRole(TrackerRole.RIGHT_HAND, trackers.hands())
|
||||
}
|
||||
vrcOSCConfig.oscqueryEnabled = req.vrcOsc().oscqueryEnabled()
|
||||
|
||||
val vrcOscHandler = api.server.vrcOSCHandler
|
||||
vrcOscHandler.refreshSettings(true)
|
||||
}
|
||||
|
||||
if (req.vmcOsc() != null) {
|
||||
val vmcConfig = api.server.configManager
|
||||
.vrConfig
|
||||
.vmc
|
||||
val vmcHandler = api.server.vMCHandler
|
||||
val osc = req.vmcOsc().oscSettings()
|
||||
|
||||
if (osc != null) {
|
||||
vmcConfig.enabled = osc.enabled()
|
||||
vmcConfig.portIn = osc.portIn()
|
||||
vmcConfig.portOut = osc.portOut()
|
||||
vmcConfig.address = osc.address()
|
||||
api.server.configManager.settings.update {
|
||||
it.copy(
|
||||
vmc = if (osc != null) {
|
||||
VMCConfig(
|
||||
enabled = osc.enabled(),
|
||||
portIn = osc.portIn(),
|
||||
portOut = osc.portOut(),
|
||||
address = osc.address(),
|
||||
vrmJson = if (req.vmcOsc().vrmJson() != null) req.vmcOsc().vrmJson().ifEmpty { null } else it.vmc.vrmJson,
|
||||
anchorHip = req.vmcOsc().anchorHip(),
|
||||
mirrorTracking = req.vmcOsc().mirrorTracking(),
|
||||
)
|
||||
} else {
|
||||
it.vmc
|
||||
},
|
||||
)
|
||||
}
|
||||
if (req.vmcOsc().vrmJson() != null) {
|
||||
vmcConfig.vrmJson = req.vmcOsc().vrmJson().ifEmpty { null }
|
||||
}
|
||||
vmcConfig.anchorHip = req.vmcOsc().anchorHip()
|
||||
vmcConfig.mirrorTracking = req.vmcOsc().mirrorTracking()
|
||||
|
||||
vmcHandler.refreshSettings(true)
|
||||
}
|
||||
|
||||
if (req.tapDetectionSettings() != null) {
|
||||
val tapDetectionConfig = api.server.configManager
|
||||
.vrConfig
|
||||
.tapDetection
|
||||
val tapDetectionSettings = req.tapDetectionSettings()
|
||||
|
||||
if (tapDetectionSettings != null) {
|
||||
// enable/disable tap detection
|
||||
tapDetectionConfig.yawResetEnabled = tapDetectionSettings.yawResetEnabled()
|
||||
tapDetectionConfig.fullResetEnabled = tapDetectionSettings.fullResetEnabled()
|
||||
tapDetectionConfig
|
||||
.mountingResetEnabled = tapDetectionSettings.mountingResetEnabled()
|
||||
tapDetectionConfig.setupMode = tapDetectionSettings.setupMode()
|
||||
|
||||
// set number of trackers that can have high accel before taps
|
||||
// are rejected
|
||||
if (tapDetectionSettings.hasNumberTrackersOverThreshold()) {
|
||||
tapDetectionConfig
|
||||
.numberTrackersOverThreshold = tapDetectionSettings.numberTrackersOverThreshold()
|
||||
api.server.configManager.settings.update {
|
||||
it.copy(
|
||||
tapDetection = TapDetectionConfig(
|
||||
yawResetEnabled = tapDetectionSettings.yawResetEnabled(),
|
||||
fullResetEnabled = tapDetectionSettings.fullResetEnabled(),
|
||||
mountingResetEnabled = tapDetectionSettings.mountingResetEnabled(),
|
||||
setupMode = tapDetectionSettings.setupMode(),
|
||||
numberTrackersOverThreshold = tapDetectionSettings.numberTrackersOverThreshold(),
|
||||
yawResetDelay = tapDetectionSettings.yawResetDelay(),
|
||||
fullResetDelay = tapDetectionSettings.fullResetDelay(),
|
||||
mountingResetDelay = tapDetectionSettings.mountingResetDelay(),
|
||||
yawResetTaps = tapDetectionSettings.yawResetTaps(),
|
||||
fullResetTaps = tapDetectionSettings.fullResetTaps(),
|
||||
mountingResetTaps = tapDetectionSettings.mountingResetTaps(),
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// set tap detection delays
|
||||
if (tapDetectionSettings.hasYawResetDelay()) {
|
||||
tapDetectionConfig.yawResetDelay = tapDetectionSettings.yawResetDelay()
|
||||
}
|
||||
if (tapDetectionSettings.hasFullResetDelay()) {
|
||||
tapDetectionConfig.fullResetDelay = tapDetectionSettings.fullResetDelay()
|
||||
}
|
||||
if (tapDetectionSettings.hasMountingResetDelay()) {
|
||||
tapDetectionConfig
|
||||
.mountingResetDelay = tapDetectionSettings.mountingResetDelay()
|
||||
}
|
||||
|
||||
// set the number of taps required for each action
|
||||
if (tapDetectionSettings.hasYawResetTaps()) {
|
||||
tapDetectionConfig
|
||||
.yawResetTaps = tapDetectionSettings.yawResetTaps()
|
||||
}
|
||||
if (tapDetectionSettings.hasFullResetTaps()) {
|
||||
tapDetectionConfig
|
||||
.fullResetTaps = tapDetectionSettings.fullResetTaps()
|
||||
}
|
||||
if (tapDetectionSettings.hasMountingResetTaps()) {
|
||||
tapDetectionConfig
|
||||
.mountingResetTaps = tapDetectionSettings.mountingResetTaps()
|
||||
}
|
||||
|
||||
api.server.humanPoseManager.updateTapDetectionConfig()
|
||||
}
|
||||
}
|
||||
@@ -212,7 +195,6 @@ class RPCSettingsHandler(var rpcHandler: RPCHandler, var api: ProtocolAPI) {
|
||||
val modelSettings = req.modelSettings()
|
||||
if (modelSettings != null) {
|
||||
val hpm = api.server.humanPoseManager
|
||||
val legTweaksConfig = api.server.configManager.vrConfig.legTweaks
|
||||
val toggles = modelSettings.toggles()
|
||||
val ratios = modelSettings.ratios()
|
||||
val legTweaks = modelSettings.legTweaks()
|
||||
@@ -310,16 +292,27 @@ class RPCSettingsHandler(var rpcHandler: RPCHandler, var api: ProtocolAPI) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (legTweaks != null) {
|
||||
if (legTweaks.hasCorrectionStrength()) {
|
||||
legTweaksConfig.correctionStrength = legTweaks.correctionStrength()
|
||||
api.server.configManager.settings.update {
|
||||
it.copy(legTweaks = it.legTweaks.copy(
|
||||
correctionStrength = legTweaks.correctionStrength()
|
||||
))
|
||||
}
|
||||
api.server.humanPoseManager.updateLegTweaksConfig()
|
||||
}
|
||||
api.server.humanPoseManager.updateLegTweaksConfig()
|
||||
}
|
||||
|
||||
modelSettings.skeletonHeight()?.let {
|
||||
api.server.configManager.vrConfig.skeleton.hmdHeight = it.hmdHeight()
|
||||
api.server.configManager.vrConfig.skeleton.floorHeight = it.floorHeight()
|
||||
modelSettings.skeletonHeight()?.let { skeletonHeight ->
|
||||
api.server.configManager.user.update {
|
||||
it.copy(
|
||||
skeleton = it.skeleton.copy(
|
||||
hmdHeight = skeletonHeight.hmdHeight(),
|
||||
floorHeight = skeletonHeight.floorHeight()
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
hpm.saveConfig()
|
||||
@@ -327,55 +320,67 @@ class RPCSettingsHandler(var rpcHandler: RPCHandler, var api: ProtocolAPI) {
|
||||
|
||||
val autoBoneSettings = req.autoBoneSettings()
|
||||
if (autoBoneSettings != null) {
|
||||
val autoBoneConfig = api.server.configManager
|
||||
.vrConfig
|
||||
.autoBone
|
||||
|
||||
val autoBoneConfig = api.server.configManager.settings.get().autoBone
|
||||
RPCSettingsBuilder.readAutoBoneSettings(autoBoneSettings, autoBoneConfig)
|
||||
}
|
||||
|
||||
if (req.resetsSettings() != null) {
|
||||
val resetsConfig = api.server.configManager
|
||||
.vrConfig
|
||||
.resetsConfig
|
||||
val mode = ArmsResetModes
|
||||
.fromId(max(req.resetsSettings().armsMountingResetMode(), 0))
|
||||
if (mode != null) {
|
||||
resetsConfig.mode = mode
|
||||
api.server.configManager.settings.update {
|
||||
it.copy(
|
||||
resetsConfig = ResetsConfig(
|
||||
mode = ArmsResetMode.fromId(max(req.resetsSettings().armsMountingResetMode(), 0)) ?: ArmsResetMode.BACK,
|
||||
resetMountingFeet = req.resetsSettings().resetMountingFeet(),
|
||||
saveMountingReset = req.resetsSettings().saveMountingReset(),
|
||||
yawResetSmoothTime = req.resetsSettings().yawResetSmoothTime(),
|
||||
resetHmdPitch = req.resetsSettings().resetHmdPitch(),
|
||||
)
|
||||
)
|
||||
}
|
||||
resetsConfig.resetMountingFeet = req.resetsSettings().resetMountingFeet()
|
||||
resetsConfig.saveMountingReset = req.resetsSettings().saveMountingReset()
|
||||
resetsConfig.yawResetSmoothTime = req.resetsSettings().yawResetSmoothTime()
|
||||
resetsConfig.resetHmdPitch = req.resetsSettings().resetHmdPitch()
|
||||
|
||||
resetsConfig.updateTrackersResetsSettings()
|
||||
}
|
||||
|
||||
if (req.stayAligned() != null) {
|
||||
val config = api.server.configManager.vrConfig.stayAlignedConfig
|
||||
val requestConfig = req.stayAligned()
|
||||
config.enabled = requestConfig.enabled()
|
||||
config.hideYawCorrection = requestConfig.hideYawCorrection()
|
||||
config.standingRelaxedPose.enabled = requestConfig.standingEnabled()
|
||||
config.standingRelaxedPose.upperLegAngleInDeg = requestConfig.standingUpperLegAngle()
|
||||
config.standingRelaxedPose.lowerLegAngleInDeg = requestConfig.standingLowerLegAngle()
|
||||
config.standingRelaxedPose.footAngleInDeg = requestConfig.standingFootAngle()
|
||||
config.sittingRelaxedPose.enabled = requestConfig.sittingEnabled()
|
||||
config.sittingRelaxedPose.upperLegAngleInDeg = requestConfig.sittingUpperLegAngle()
|
||||
config.sittingRelaxedPose.lowerLegAngleInDeg = requestConfig.sittingLowerLegAngle()
|
||||
config.sittingRelaxedPose.footAngleInDeg = requestConfig.sittingFootAngle()
|
||||
config.flatRelaxedPose.enabled = requestConfig.flatEnabled()
|
||||
config.flatRelaxedPose.upperLegAngleInDeg = requestConfig.flatUpperLegAngle()
|
||||
config.flatRelaxedPose.lowerLegAngleInDeg = requestConfig.flatLowerLegAngle()
|
||||
config.flatRelaxedPose.footAngleInDeg = requestConfig.flatFootAngle()
|
||||
api.server.configManager.settings.update {
|
||||
it.copy(
|
||||
stayAlignedConfig = it.stayAlignedConfig.copy(
|
||||
enabled = requestConfig.enabled(),
|
||||
hideYawCorrection = requestConfig.hideYawCorrection(),
|
||||
standingRelaxedPose = it.stayAlignedConfig.standingRelaxedPose.copy(
|
||||
enabled = requestConfig.standingEnabled(),
|
||||
upperLegAngleInDeg = requestConfig.standingUpperLegAngle(),
|
||||
lowerLegAngleInDeg = requestConfig.standingLowerLegAngle(),
|
||||
footAngleInDeg = requestConfig.standingFootAngle(),
|
||||
),
|
||||
sittingRelaxedPose = it.stayAlignedConfig.sittingRelaxedPose.copy(
|
||||
enabled = requestConfig.sittingEnabled(),
|
||||
upperLegAngleInDeg = requestConfig.sittingUpperLegAngle(),
|
||||
lowerLegAngleInDeg = requestConfig.sittingLowerLegAngle(),
|
||||
footAngleInDeg = requestConfig.sittingFootAngle(),
|
||||
),
|
||||
flatRelaxedPose = it.stayAlignedConfig.flatRelaxedPose.copy(
|
||||
enabled = requestConfig.flatEnabled(),
|
||||
upperLegAngleInDeg = requestConfig.flatUpperLegAngle(),
|
||||
lowerLegAngleInDeg = requestConfig.flatLowerLegAngle(),
|
||||
footAngleInDeg = requestConfig.flatFootAngle(),
|
||||
),
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (req.hidSettings() != null) {
|
||||
val config = api.server.configManager.vrConfig.hidConfig
|
||||
val requestConfig = req.hidSettings()
|
||||
config.trackersOverHID = requestConfig.trackersOverHid()
|
||||
api.server.configManager.settings.update {
|
||||
it.copy(hidConfig = it.hidConfig.copy(
|
||||
trackersOverHID = requestConfig.trackersOverHid()
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
api.server.configManager.saveConfig()
|
||||
api.server.configManager.settings.save()
|
||||
api.server.configManager.user.save()
|
||||
}
|
||||
|
||||
fun onSettingsResetRequest(conn: GenericConnection, messageHeader: RpcMessageHeader?) {
|
||||
|
||||
@@ -56,9 +56,7 @@ class RPCHandshakeHandler(
|
||||
conn: GenericConnection,
|
||||
messageHeader: RpcMessageHeader,
|
||||
) {
|
||||
val req =
|
||||
messageHeader.message(AddUnknownDeviceRequest()) as AddUnknownDeviceRequest?
|
||||
?: return
|
||||
val req = messageHeader.message(AddUnknownDeviceRequest()) as AddUnknownDeviceRequest
|
||||
|
||||
this.api.server.configManager.vrConfig.addKnownDevice(
|
||||
req.macAddress() ?: return,
|
||||
@@ -70,8 +68,7 @@ class RPCHandshakeHandler(
|
||||
conn: GenericConnection,
|
||||
messageHeader: RpcMessageHeader,
|
||||
) {
|
||||
val req = messageHeader.message(ForgetDeviceRequest()) as ForgetDeviceRequest?
|
||||
?: return
|
||||
val req = messageHeader.message(ForgetDeviceRequest()) as ForgetDeviceRequest
|
||||
|
||||
this.api.server.configManager.vrConfig.forgetKnownDevice(
|
||||
req.macAddress() ?: return,
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ class RPCTrackingChecklistHandler(
|
||||
fbb,
|
||||
TrackingChecklistResponseT().apply {
|
||||
steps = api.server.trackingChecklistManager.steps.toTypedArray()
|
||||
ignoredSteps = api.server.configManager.vrConfig.trackingChecklist.ignoredStepsIds.toIntArray()
|
||||
ignoredSteps = api.server.configManager.settings.get().trackingChecklist.ignoredStepsIds.toIntArray()
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.jme3.math.FastMath
|
||||
import dev.slimevr.VRServer
|
||||
import dev.slimevr.VRServer.Companion.getNextLocalTrackerId
|
||||
import dev.slimevr.autobone.errors.BodyProportionError
|
||||
import dev.slimevr.config.ConfigManager
|
||||
import dev.slimevr.tracking.processor.config.SkeletonConfigManager
|
||||
import dev.slimevr.tracking.processor.config.SkeletonConfigOffsets
|
||||
import dev.slimevr.tracking.processor.config.SkeletonConfigToggles
|
||||
@@ -225,8 +224,8 @@ class HumanPoseManager(val server: VRServer?) {
|
||||
connectComputedHumanPoseTrackers()
|
||||
}
|
||||
|
||||
fun loadFromConfig(configManager: ConfigManager) {
|
||||
skeletonConfigManager.loadFromConfig(configManager)
|
||||
fun loadFromConfig(configProfileHandler: ConfigProfileHandler) {
|
||||
skeletonConfigManager.loadFromConfig(configProfileHandler)
|
||||
}
|
||||
|
||||
@VRServerThread
|
||||
@@ -570,8 +569,10 @@ class HumanPoseManager(val server: VRServer?) {
|
||||
|
||||
@JvmOverloads
|
||||
fun resetTrackersMounting(resetSourceName: String?, bodyParts: List<Int>? = null) {
|
||||
val resetsConfig = server?.configManager?.settings?.get()?.resetsConfig
|
||||
|
||||
val finalBodyParts = bodyParts
|
||||
?: if (server?.configManager?.vrConfig?.resetsConfig?.resetMountingFeet == true) {
|
||||
?: if (resetsConfig?.resetMountingFeet == true) {
|
||||
TrackerUtils.allBodyPartsButFingers
|
||||
} else {
|
||||
TrackerUtils.allBodyPartsButFingersAndFeets
|
||||
@@ -602,11 +603,15 @@ class HumanPoseManager(val server: VRServer?) {
|
||||
fun setFloorClipEnabled(value: Boolean) {
|
||||
skeleton.setFloorclipEnabled(value)
|
||||
if (server != null) {
|
||||
server.configManager
|
||||
.vrConfig
|
||||
.skeleton
|
||||
.getToggles()[SkeletonConfigToggles.FLOOR_CLIP.configKey] = value
|
||||
server.configManager.saveConfig()
|
||||
server.configManager.user.update {
|
||||
// TODO: NEED TO CHECK IF THAT ACTCHUALY WORK
|
||||
it.skeleton.toggles[SkeletonConfigToggles.FLOR_CLIP.configKey] = value
|
||||
it.copy(
|
||||
skeleton = it.skeleton.copy(
|
||||
toggles = it.skeleton.toggles
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -614,11 +619,15 @@ class HumanPoseManager(val server: VRServer?) {
|
||||
fun setSkatingCorrectionEnabled(value: Boolean) {
|
||||
skeleton.setSkatingCorrectionEnabled(value)
|
||||
if (server != null) {
|
||||
server.configManager
|
||||
.vrConfig
|
||||
.skeleton
|
||||
.getToggles()[SkeletonConfigToggles.SKATING_CORRECTION.configKey] = value
|
||||
server.configManager.saveConfig()
|
||||
server.configManager.user.update {
|
||||
// TODO: NEED TO CHECK IF THAT ACTCHUALY WORK
|
||||
it.skeleton.toggles[SkeletonConfigToggles.SKATING_CORRECTION.configKey] = value
|
||||
it.copy(
|
||||
skeleton = it.skeleton.copy(
|
||||
toggles = it.skeleton.toggles
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+24
-23
@@ -4,7 +4,6 @@ import dev.slimevr.VRServer.Companion.instance
|
||||
import dev.slimevr.VRServer.Companion.instanceInitialized
|
||||
import dev.slimevr.autobone.AutoBone
|
||||
import dev.slimevr.autobone.errors.BodyProportionError.Companion.proportionLimitMap
|
||||
import dev.slimevr.config.ConfigManager
|
||||
import dev.slimevr.tracking.processor.BoneType
|
||||
import dev.slimevr.tracking.processor.HumanPoseManager
|
||||
import io.github.axisangles.ktmath.Vector3
|
||||
@@ -422,7 +421,7 @@ class SkeletonConfigManager(
|
||||
instance.configManager
|
||||
.vrConfig
|
||||
.skeleton
|
||||
.getToggles()
|
||||
.toggles
|
||||
.remove(value.configKey)
|
||||
}
|
||||
}
|
||||
@@ -445,7 +444,7 @@ class SkeletonConfigManager(
|
||||
instance.configManager
|
||||
.vrConfig
|
||||
.skeleton
|
||||
.getValues()
|
||||
.values
|
||||
.remove(value.configKey)
|
||||
}
|
||||
}
|
||||
@@ -458,7 +457,7 @@ class SkeletonConfigManager(
|
||||
}
|
||||
|
||||
fun resetOffset(config: SkeletonConfigOffsets) {
|
||||
val height = humanPoseManager?.server?.configManager?.vrConfig?.skeleton?.userHeight ?: -1f
|
||||
val height = humanPoseManager?.server?.configManager?.user?.get()?.skeleton?.userHeight ?: -1f
|
||||
// Only scale if the height is within range
|
||||
if (height > AutoBone.MIN_HEIGHT) {
|
||||
val proportionLimiter = proportionLimitMap[config]
|
||||
@@ -475,11 +474,11 @@ class SkeletonConfigManager(
|
||||
}
|
||||
}
|
||||
|
||||
fun loadFromConfig(configManager: ConfigManager) {
|
||||
val skeletonConfig = configManager.vrConfig.skeleton
|
||||
fun loadFromConfig(configProfileHandler: ConfigProfileHandler) {
|
||||
val skeletonConfig = configProfileHandler.vrConfig.skeleton
|
||||
|
||||
// Load offsets
|
||||
val offsets = skeletonConfig.getOffsets()
|
||||
val offsets = skeletonConfig.offsets
|
||||
for (configValue in SkeletonConfigOffsets.values) {
|
||||
val offset = offsets[configValue.configKey]
|
||||
if (offset != null) {
|
||||
@@ -490,7 +489,7 @@ class SkeletonConfigManager(
|
||||
}
|
||||
|
||||
// Load toggles
|
||||
val toggles = skeletonConfig.getToggles()
|
||||
val toggles = skeletonConfig.toggles
|
||||
for (configValue in SkeletonConfigToggles.values) {
|
||||
val toggle = toggles[configValue.configKey]
|
||||
if (toggle != null) {
|
||||
@@ -501,7 +500,7 @@ class SkeletonConfigManager(
|
||||
}
|
||||
|
||||
// Load values
|
||||
val values = skeletonConfig.getValues()
|
||||
val values = skeletonConfig.values
|
||||
for (configValue in SkeletonConfigValues.values) {
|
||||
val value = values[configValue.configKey]
|
||||
if (value != null) {
|
||||
@@ -520,23 +519,25 @@ class SkeletonConfigManager(
|
||||
fun save() {
|
||||
require(instanceInitialized) { "VRServer instance is not initialized, config cannot be saved." }
|
||||
|
||||
val skeletonConfig = instance.configManager
|
||||
.vrConfig
|
||||
.skeleton
|
||||
instance.configManager.user.update {
|
||||
val skeletonConfig = it.skeleton.copy()
|
||||
|
||||
// Write all possible values to keep consistent even if defaults changed
|
||||
for (value in SkeletonConfigOffsets.values) {
|
||||
skeletonConfig.getOffsets()[value.configKey] = getOffset(value)
|
||||
}
|
||||
// Write all possible values to keep consistent even if defaults changed
|
||||
for (value in SkeletonConfigOffsets.values) {
|
||||
skeletonConfig.offsets[value.configKey] = getOffset(value)
|
||||
}
|
||||
|
||||
// Only write changed values to keep using defaults if not changed
|
||||
for (value in SkeletonConfigToggles.values) {
|
||||
if (changedToggles[value.ordinal]) skeletonConfig.getToggles()[value.configKey] = getToggle(value)
|
||||
}
|
||||
// Only write changed values to keep using defaults if not changed
|
||||
for (value in SkeletonConfigToggles.values) {
|
||||
if (changedToggles[value.ordinal]) skeletonConfig.toggles[value.configKey] = getToggle(value)
|
||||
}
|
||||
|
||||
// Only write changed values to keep using defaults if not changed
|
||||
for (value in SkeletonConfigValues.values) {
|
||||
if (changedValues[value.ordinal]) skeletonConfig.getValues()[value.configKey] = getValue(value)
|
||||
// Only write changed values to keep using defaults if not changed
|
||||
for (value in SkeletonConfigValues.values) {
|
||||
if (changedValues[value.ordinal]) skeletonConfig.values[value.configKey] = getValue(value)
|
||||
}
|
||||
|
||||
it.copy(skeleton = skeletonConfig)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dev.slimevr.tracking.processor.skeleton
|
||||
|
||||
import dev.slimevr.VRServer
|
||||
import dev.slimevr.config.MountingMethods
|
||||
import dev.slimevr.config.MountingMethod
|
||||
import dev.slimevr.config.StayAlignedConfig
|
||||
import dev.slimevr.tracking.processor.Bone
|
||||
import dev.slimevr.tracking.processor.BoneType
|
||||
@@ -1642,7 +1642,7 @@ class HumanSkeleton(
|
||||
|
||||
if (humanPoseManager.server != null) {
|
||||
humanPoseManager.server.configManager.vrConfig.resetsConfig.lastMountingMethod =
|
||||
MountingMethods.AUTOMATIC
|
||||
MountingMethod.AUTOMATIC
|
||||
if (!humanPoseManager.server.trackingChecklistManager.resetMountingCompleted) {
|
||||
humanPoseManager.server.trackingChecklistManager.resetMountingCompleted = bodyParts.any { it ->
|
||||
val defaultParts = if (humanPoseManager.server.configManager.vrConfig.resetsConfig.resetMountingFeet) {
|
||||
|
||||
+4
-2
@@ -15,13 +15,12 @@ class TapDetectionManager(
|
||||
var fullResetDetector: TapDetection? = null
|
||||
var mountingResetDetector: TapDetection? = null
|
||||
|
||||
var config = server.configManager.vrConfig.tapDetection
|
||||
|
||||
init {
|
||||
refresh()
|
||||
}
|
||||
|
||||
fun registerSingleTapDetectors() {
|
||||
val config = server.configManager.settings.get().tapDetection
|
||||
for (tracker in server.allTrackers) {
|
||||
tapDetectors.add(
|
||||
TapDetection(skeleton, tracker, config.numberTrackersOverThreshold, 2) {
|
||||
@@ -32,6 +31,7 @@ class TapDetectionManager(
|
||||
}
|
||||
|
||||
fun registerResetsDetectors() {
|
||||
val config = server.configManager.settings.get().tapDetection
|
||||
val yawTracker = yawResetTracker
|
||||
yawResetDetector = if (yawTracker != null && config.yawResetEnabled) {
|
||||
TapDetection(skeleton, yawTracker, config.numberTrackersOverThreshold, config.yawResetTaps) {
|
||||
@@ -72,6 +72,8 @@ class TapDetectionManager(
|
||||
}
|
||||
|
||||
fun update() {
|
||||
val config = server.configManager.settings.get().tapDetection
|
||||
|
||||
// We disable the resets detectors during the assignment phase so you cant
|
||||
// trigger a reset while assigning
|
||||
if (config.setupMode) {
|
||||
|
||||
+9
-3
@@ -12,7 +12,6 @@ import solarxr_protocol.rpc.UserHeightRecordingStatusResponseT
|
||||
import java.util.concurrent.CopyOnWriteArrayList
|
||||
import kotlin.math.PI
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.max
|
||||
import kotlin.math.sqrt
|
||||
|
||||
/**
|
||||
@@ -148,8 +147,15 @@ class UserHeightCalibration(val server: VRServer, val humanPoseManager: HumanPos
|
||||
}
|
||||
|
||||
fun applyCalibration() {
|
||||
server.configManager.vrConfig.skeleton.hmdHeight = currentHeight
|
||||
server.configManager.vrConfig.skeleton.floorHeight = 0f
|
||||
|
||||
server.configManager.user.update {
|
||||
it.copy(
|
||||
skeleton = it.skeleton.copy(
|
||||
hmdHeight = currentHeight,
|
||||
floorHeight = 0f
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
server.humanPoseManager.resetOffsets()
|
||||
server.humanPoseManager.saveConfig()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.slimevr.tracking.trackers
|
||||
|
||||
import dev.slimevr.VRServer
|
||||
import dev.slimevr.config.ConfigManager
|
||||
import dev.slimevr.config.TrackerConfig
|
||||
import dev.slimevr.tracking.processor.stayaligned.trackers.StayAlignedTrackerState
|
||||
import dev.slimevr.tracking.trackers.TrackerPosition.Companion.getByDesignation
|
||||
@@ -192,7 +193,11 @@ class Tracker @JvmOverloads constructor(
|
||||
/**
|
||||
* Reads/loads from the given config
|
||||
*/
|
||||
fun readConfig(config: TrackerConfig) {
|
||||
fun readConfig(configManager: ConfigManager) {
|
||||
val settings = configManager.settings.get();
|
||||
val config = configManager.user.get().trackers[name] ?: TrackerConfig(this)
|
||||
|
||||
if (!userEditable) return;
|
||||
config.customName?.let {
|
||||
customName = it
|
||||
}
|
||||
@@ -213,6 +218,13 @@ class Tracker @JvmOverloads constructor(
|
||||
resetsHandler.allowDriftCompensation = it
|
||||
}
|
||||
}
|
||||
resetsHandler.readResetConfig(settings.resetsConfig)
|
||||
if (allowReset) {
|
||||
saveMountingResetOrientation(config)
|
||||
}
|
||||
if (allowFiltering) {
|
||||
filteringHandler.readFilteringConfig(settings.filters, getRotation())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,8 +2,7 @@ package dev.slimevr.tracking.trackers
|
||||
|
||||
import com.jme3.math.FastMath
|
||||
import dev.slimevr.VRServer
|
||||
import dev.slimevr.config.ArmsResetModes
|
||||
import dev.slimevr.config.DriftCompensationConfig
|
||||
import dev.slimevr.config.ArmsResetMode
|
||||
import dev.slimevr.config.ResetsConfig
|
||||
import dev.slimevr.filtering.CircularArrayList
|
||||
import dev.slimevr.tracking.trackers.udp.TrackerDataType
|
||||
@@ -37,7 +36,7 @@ class TrackerResetsHandler(val tracker: Tracker) {
|
||||
private var compensateDrift = false
|
||||
private var driftPrediction = false
|
||||
private var driftCompensationEnabled = false
|
||||
private var armsResetMode = ArmsResetModes.BACK
|
||||
private var armsResetMode = ArmsResetMode.BACK
|
||||
private var yawResetSmoothTime = 0.0f
|
||||
var saveMountingReset = false
|
||||
var resetHmdPitch = false
|
||||
@@ -108,23 +107,6 @@ class TrackerResetsHandler(val tracker: Tracker) {
|
||||
*/
|
||||
private var tposeDownFix = Quaternion.IDENTITY
|
||||
|
||||
/**
|
||||
* Reads/loads drift compensation settings from given config
|
||||
*/
|
||||
fun readDriftCompensationConfig(config: DriftCompensationConfig) {
|
||||
compensateDrift = false
|
||||
driftPrediction = config.prediction
|
||||
driftAmount = config.amount
|
||||
val maxResets = config.maxResets
|
||||
|
||||
if (compensateDrift && maxResets != driftQuats.capacity()) {
|
||||
driftQuats = CircularArrayList<Quaternion>(maxResets)
|
||||
driftTimes = CircularArrayList<Long>(maxResets)
|
||||
}
|
||||
|
||||
refreshDriftCompensationEnabled()
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears drift compensation data
|
||||
*/
|
||||
@@ -252,9 +234,9 @@ class TrackerResetsHandler(val tracker: Tracker) {
|
||||
}
|
||||
|
||||
// Adjust for T-Pose (down)
|
||||
tposeDownFix = if (((tracker.trackerPosition.isLeftArm() || tracker.trackerPosition.isLeftFinger()) && armsResetMode == ArmsResetModes.TPOSE_DOWN)) {
|
||||
tposeDownFix = if (((tracker.trackerPosition.isLeftArm() || tracker.trackerPosition.isLeftFinger()) && armsResetMode == ArmsResetMode.TPOSE_DOWN)) {
|
||||
EulerAngles(EulerOrder.YZX, 0f, 0f, -FastMath.HALF_PI).toQuaternion()
|
||||
} else if (((tracker.trackerPosition.isRightArm() || tracker.trackerPosition.isRightFinger()) && armsResetMode == ArmsResetModes.TPOSE_DOWN)) {
|
||||
} else if (((tracker.trackerPosition.isRightArm() || tracker.trackerPosition.isRightFinger()) && armsResetMode == ArmsResetMode.TPOSE_DOWN)) {
|
||||
EulerAngles(EulerOrder.YZX, 0f, 0f, FastMath.HALF_PI).toQuaternion()
|
||||
} else {
|
||||
Quaternion.IDENTITY
|
||||
@@ -414,15 +396,15 @@ class TrackerResetsHandler(val tracker: Tracker) {
|
||||
var yawAngle = atan2(rotVector.x, rotVector.z)
|
||||
|
||||
// Adjust for T-Pose and fingers
|
||||
if ((tracker.trackerPosition.isLeftArm() && armsResetMode == ArmsResetModes.TPOSE_DOWN) ||
|
||||
(tracker.trackerPosition.isRightArm() && armsResetMode == ArmsResetModes.TPOSE_UP) ||
|
||||
if ((tracker.trackerPosition.isLeftArm() && armsResetMode == ArmsResetMode.TPOSE_DOWN) ||
|
||||
(tracker.trackerPosition.isRightArm() && armsResetMode == ArmsResetMode.TPOSE_UP) ||
|
||||
tracker.trackerPosition.isLeftFinger()
|
||||
) {
|
||||
// Tracker goes right
|
||||
yawAngle -= FastMath.HALF_PI
|
||||
}
|
||||
if ((tracker.trackerPosition.isLeftArm() && armsResetMode == ArmsResetModes.TPOSE_UP) ||
|
||||
(tracker.trackerPosition.isRightArm() && armsResetMode == ArmsResetModes.TPOSE_DOWN) ||
|
||||
if ((tracker.trackerPosition.isLeftArm() && armsResetMode == ArmsResetMode.TPOSE_UP) ||
|
||||
(tracker.trackerPosition.isRightArm() && armsResetMode == ArmsResetMode.TPOSE_DOWN) ||
|
||||
tracker.trackerPosition.isRightFinger()
|
||||
) {
|
||||
// Tracker goes left
|
||||
@@ -430,8 +412,8 @@ class TrackerResetsHandler(val tracker: Tracker) {
|
||||
}
|
||||
|
||||
// Adjust for forward/back arms and thighs
|
||||
val isLowerArmBack = armsResetMode == ArmsResetModes.BACK && (tracker.trackerPosition.isLeftLowerArm() || tracker.trackerPosition.isRightLowerArm())
|
||||
val isArmForward = armsResetMode == ArmsResetModes.FORWARD && (tracker.trackerPosition.isLeftArm() || tracker.trackerPosition.isRightArm())
|
||||
val isLowerArmBack = armsResetMode == ArmsResetMode.BACK && (tracker.trackerPosition.isLeftLowerArm() || tracker.trackerPosition.isRightLowerArm())
|
||||
val isArmForward = armsResetMode == ArmsResetMode.FORWARD && (tracker.trackerPosition.isLeftArm() || tracker.trackerPosition.isRightArm())
|
||||
if (!tracker.trackerPosition.isThigh() && !isArmForward && !isLowerArmBack) {
|
||||
// Tracker goes back
|
||||
yawAngle -= FastMath.PI
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package dev.slimevr.tracking.trackers
|
||||
|
||||
import java.util.Locale
|
||||
|
||||
/**
|
||||
* The tracker role classifies the position and the role of a tracker on user's
|
||||
* body or playspace (like CAMERA or BEACON). Tracker roles are hints for
|
||||
@@ -34,9 +36,12 @@ enum class TrackerRole(val id: Int, val roleHint: String, val viveRole: String)
|
||||
;
|
||||
|
||||
companion object {
|
||||
private val byId = values().associateBy { it.id }
|
||||
private val byId = TrackerRole.entries.associateBy { it.id }
|
||||
|
||||
@JvmStatic
|
||||
fun getById(id: Int): TrackerRole? = byId[id]
|
||||
}
|
||||
}
|
||||
|
||||
val TrackerRole.toKey: String
|
||||
get() = name.lowercase(Locale.getDefault())
|
||||
@@ -3,7 +3,6 @@ package dev.slimevr.tracking.trackers.udp
|
||||
import com.jme3.math.FastMath
|
||||
import dev.slimevr.NetworkProtocol
|
||||
import dev.slimevr.VRServer
|
||||
import dev.slimevr.config.config
|
||||
import dev.slimevr.protocol.rpc.MAG_TIMEOUT
|
||||
import dev.slimevr.tracking.trackers.*
|
||||
import io.eiren.util.Util
|
||||
@@ -540,18 +539,19 @@ class TrackersUDPServer(private val port: Int, name: String, private val tracker
|
||||
is UDPPacket21UserAction -> {
|
||||
if (connection == null) return
|
||||
var name = ""
|
||||
val resetsConfig = VRServer.instance.configManager.settings.get().resetsConfig;
|
||||
when (packet.type) {
|
||||
UDPPacket21UserAction.RESET_FULL -> {
|
||||
name = "Full reset"
|
||||
VRServer.instance.scheduleResetTrackersFull(
|
||||
RESET_SOURCE_NAME,
|
||||
(VRServer.instance.configManager.vrConfig.resetsConfig.fullResetDelay * 1000).toLong(),
|
||||
(resetsConfig.fullResetDelay * 1000).toLong(),
|
||||
)
|
||||
}
|
||||
|
||||
UDPPacket21UserAction.RESET_YAW -> {
|
||||
name = "Yaw reset"
|
||||
VRServer.instance.scheduleResetTrackersYaw(RESET_SOURCE_NAME, (VRServer.instance.configManager.vrConfig.resetsConfig.yawResetDelay * 1000).toLong())
|
||||
VRServer.instance.scheduleResetTrackersYaw(RESET_SOURCE_NAME, (resetsConfig.yawResetDelay * 1000).toLong())
|
||||
}
|
||||
|
||||
UDPPacket21UserAction.RESET_MOUNTING -> {
|
||||
@@ -560,7 +560,7 @@ class TrackersUDPServer(private val port: Int, name: String, private val tracker
|
||||
.instance
|
||||
.resetHandler
|
||||
.sendStarted(ResetType.Mounting)
|
||||
VRServer.instance.scheduleResetTrackersMounting(RESET_SOURCE_NAME, (VRServer.instance.configManager.vrConfig.resetsConfig.mountingResetDelay * 1000).toLong())
|
||||
VRServer.instance.scheduleResetTrackersMounting(RESET_SOURCE_NAME, (resetsConfig.mountingResetDelay * 1000).toLong())
|
||||
}
|
||||
|
||||
UDPPacket21UserAction.PAUSE_TRACKING -> {
|
||||
|
||||
+23
-12
@@ -2,7 +2,7 @@ package dev.slimevr.trackingchecklist
|
||||
|
||||
import dev.slimevr.VRServer
|
||||
import dev.slimevr.bridge.ISteamVRBridge
|
||||
import dev.slimevr.config.MountingMethods
|
||||
import dev.slimevr.config.MountingMethod
|
||||
import dev.slimevr.games.vrchat.VRCConfigListener
|
||||
import dev.slimevr.games.vrchat.VRCConfigRecommendedValues
|
||||
import dev.slimevr.games.vrchat.VRCConfigValidity
|
||||
@@ -120,7 +120,7 @@ class TrackingChecklistManager(private val vrServer: VRServer) : VRCConfigListen
|
||||
TrackingChecklistStepT().apply {
|
||||
id = TrackingChecklistStepId.MOUNTING_CALIBRATION
|
||||
valid = false
|
||||
enabled = vrServer.configManager.vrConfig.resetsConfig.lastMountingMethod == MountingMethods.AUTOMATIC
|
||||
enabled = false
|
||||
optional = false
|
||||
ignorable = true
|
||||
visibility = TrackingChecklistStepVisibility.ALWAYS
|
||||
@@ -171,6 +171,9 @@ class TrackingChecklistManager(private val vrServer: VRServer) : VRCConfigListen
|
||||
}
|
||||
|
||||
fun updateChecklist() {
|
||||
|
||||
val settings = vrServer.configManager.settings.get();
|
||||
|
||||
val assignedTrackers =
|
||||
vrServer.allTrackers.filter { it.trackerPosition != null && it.status != TrackerStatus.DISCONNECTED }
|
||||
val imuTrackers =
|
||||
@@ -296,17 +299,17 @@ class TrackingChecklistManager(private val vrServer: VRServer) : VRCConfigListen
|
||||
}
|
||||
|
||||
updateValidity(TrackingChecklistStepId.MOUNTING_CALIBRATION, resetMountingCompleted) {
|
||||
it.enabled = vrServer.configManager.vrConfig.resetsConfig.lastMountingMethod == MountingMethods.AUTOMATIC && imuTrackers.isNotEmpty()
|
||||
it.enabled = settings.resetsConfig.lastMountingMethod == MountingMethod.AUTOMATIC && imuTrackers.isNotEmpty()
|
||||
}
|
||||
|
||||
updateValidity(TrackingChecklistStepId.FEET_MOUNTING_CALIBRATION, feetResetMountingCompleted) {
|
||||
it.enabled =
|
||||
vrServer.configManager.vrConfig.resetsConfig.lastMountingMethod == MountingMethods.AUTOMATIC &&
|
||||
!vrServer.configManager.vrConfig.resetsConfig.resetMountingFeet &&
|
||||
settings.resetsConfig.lastMountingMethod == MountingMethod.AUTOMATIC &&
|
||||
!settings.resetsConfig.resetMountingFeet &&
|
||||
imuTrackers.any { t -> TrackerUtils.feetsBodyParts.contains(t.trackerPosition?.bodyPart) }
|
||||
}
|
||||
|
||||
updateValidity(TrackingChecklistStepId.STAY_ALIGNED_CONFIGURED, vrServer.configManager.vrConfig.stayAlignedConfig.enabled)
|
||||
updateValidity(TrackingChecklistStepId.STAY_ALIGNED_CONFIGURED, settings.stayAlignedConfig.enabled)
|
||||
|
||||
listeners.forEach { it.onStepsUpdate() }
|
||||
}
|
||||
@@ -340,12 +343,20 @@ class TrackingChecklistManager(private val vrServer: VRServer) : VRCConfigListen
|
||||
|
||||
fun ignoreStep(step: TrackingChecklistStepT, ignore: Boolean) {
|
||||
if (!step.ignorable) return
|
||||
val ignoredSteps = vrServer.configManager.vrConfig.trackingChecklist.ignoredStepsIds
|
||||
if (ignore && !ignoredSteps.contains(step.id)) {
|
||||
ignoredSteps.add(step.id)
|
||||
} else if (!ignore) {
|
||||
ignoredSteps.remove(step.id)
|
||||
|
||||
vrServer.configManager.settings.update {
|
||||
val ignoredSteps = it.trackingChecklist.ignoredStepsIds.toMutableList()
|
||||
if (ignore && !ignoredSteps.contains(step.id)) {
|
||||
ignoredSteps.add(step.id)
|
||||
} else if (!ignore) {
|
||||
ignoredSteps.remove(step.id)
|
||||
}
|
||||
|
||||
it.copy(
|
||||
trackingChecklist = it.trackingChecklist.copy(
|
||||
ignoredStepsIds = ignoredSteps
|
||||
)
|
||||
)
|
||||
}
|
||||
vrServer.configManager.saveConfig()
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package dev.slimevr.websocketapi
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode
|
||||
import dev.slimevr.VRServer
|
||||
import dev.slimevr.VRServer.Companion.getNextLocalTrackerId
|
||||
import dev.slimevr.VRServer.Companion.instance
|
||||
@@ -13,20 +11,68 @@ import io.eiren.util.collections.FastList
|
||||
import io.eiren.util.logging.LogManager
|
||||
import io.github.axisangles.ktmath.Quaternion
|
||||
import io.github.axisangles.ktmath.Vector3
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.decodeFromJsonElement
|
||||
import kotlinx.serialization.json.float
|
||||
import kotlinx.serialization.json.intOrNull
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
import org.java_websocket.WebSocket
|
||||
import org.java_websocket.handshake.ClientHandshake
|
||||
import java.util.*
|
||||
import java.util.Locale
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
// --- Data Models for Serialization ---
|
||||
|
||||
@Serializable
|
||||
data class OutgoingConfigMessage(
|
||||
val type: String = "config",
|
||||
@SerialName("tracker_id") val trackerId: String,
|
||||
val location: String?,
|
||||
@SerialName("tracker_type") val trackerType: String?,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class OutgoingPositionMessage(
|
||||
val type: String = "pos",
|
||||
val src: String = "full",
|
||||
@SerialName("tracker_id") val trackerId: String,
|
||||
val x: Float,
|
||||
val y: Float,
|
||||
val z: Float,
|
||||
val qx: Float,
|
||||
val qy: Float,
|
||||
val qz: Float,
|
||||
val qw: Float,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class IncomingActionMessage(
|
||||
val name: String,
|
||||
)
|
||||
|
||||
// --- Bridge Implementation ---
|
||||
|
||||
class WebSocketVRBridge(
|
||||
computedTrackers: List<Tracker>,
|
||||
server: VRServer,
|
||||
) : WebsocketAPI(server, server.protocolAPI),
|
||||
Bridge {
|
||||
|
||||
private val computedTrackers: List<Tracker> = FastList(computedTrackers)
|
||||
private val internalTrackers: MutableList<Tracker> = FastList(computedTrackers.size)
|
||||
private val newHMDData = AtomicBoolean(false)
|
||||
private val mapper = ObjectMapper()
|
||||
|
||||
// Global Json configuration
|
||||
private val json = Json {
|
||||
ignoreUnknownKeys = true
|
||||
encodeDefaults = true
|
||||
}
|
||||
|
||||
private val internalHMDTracker = Tracker(
|
||||
null,
|
||||
0,
|
||||
@@ -61,9 +107,7 @@ class WebSocketVRBridge(
|
||||
override fun dataRead() {
|
||||
if (newHMDData.compareAndSet(true, false)) {
|
||||
if (hmdTracker == null) {
|
||||
// Create HMD for websocket
|
||||
val hmdDevice = server.deviceManager
|
||||
.createDevice("WebSocketVRBridge", null, null)
|
||||
val hmdDevice = server.deviceManager.createDevice("WebSocketVRBridge", null, null)
|
||||
hmdTracker = Tracker(
|
||||
null,
|
||||
getNextLocalTrackerId(),
|
||||
@@ -97,112 +141,76 @@ class WebSocketVRBridge(
|
||||
|
||||
override fun onOpen(conn: WebSocket, handshake: ClientHandshake) {
|
||||
super.onOpen(conn, handshake)
|
||||
// Register trackers
|
||||
for (i in internalTrackers.indices) {
|
||||
val message = mapper.nodeFactory.objectNode()
|
||||
message.put("type", "config")
|
||||
message.put("tracker_id", "SlimeVR Tracker " + (i + 1))
|
||||
message
|
||||
.put(
|
||||
"location",
|
||||
computedTrackers[i]
|
||||
.trackerPosition
|
||||
?.trackerRole
|
||||
?.name
|
||||
?.lowercase(Locale.getDefault()),
|
||||
)
|
||||
message.put("tracker_type", message["location"].asText())
|
||||
conn.send(message.toString())
|
||||
val loc = computedTrackers[i].trackerPosition?.trackerRole?.name?.lowercase(Locale.getDefault())
|
||||
val message = OutgoingConfigMessage(
|
||||
trackerId = "SlimeVR Tracker ${i + 1}",
|
||||
location = loc,
|
||||
trackerType = loc,
|
||||
)
|
||||
conn.send(json.encodeToString(message))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onMessage(conn: WebSocket, message: String) {
|
||||
// LogManager.info(message);
|
||||
try {
|
||||
val json = mapper.readTree(message) as ObjectNode
|
||||
if (json.has("type")) {
|
||||
when (json["type"].asText()) {
|
||||
"pos" -> {
|
||||
parsePosition(json, conn)
|
||||
return
|
||||
}
|
||||
val root = json.parseToJsonElement(message).jsonObject
|
||||
val type = root["type"]?.jsonPrimitive?.content ?: return
|
||||
|
||||
"action" -> {
|
||||
parseAction(json, conn)
|
||||
return
|
||||
}
|
||||
|
||||
// TODO Ignore it for now, it should only register HMD in our test case with id 0
|
||||
"config" -> {
|
||||
LogManager.info("[WebSocket] Config received: $json")
|
||||
return
|
||||
}
|
||||
}
|
||||
when (type) {
|
||||
"pos" -> parsePosition(root, conn)
|
||||
"action" -> parseAction(root)
|
||||
"config" -> LogManager.info("[WebSocket] Config received: $message")
|
||||
else -> LogManager.warning("[WebSocket] Unrecognized message: $message")
|
||||
}
|
||||
LogManager
|
||||
.warning(
|
||||
"[WebSocket] Unrecognized message from " +
|
||||
conn.remoteSocketAddress.address.hostAddress +
|
||||
": " +
|
||||
message,
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
LogManager
|
||||
.severe(
|
||||
"[WebSocket] Exception parsing message from " +
|
||||
conn.remoteSocketAddress.address.hostAddress +
|
||||
". Message: " +
|
||||
message,
|
||||
e,
|
||||
)
|
||||
LogManager.severe("[WebSocket] Exception parsing message: $message", e)
|
||||
}
|
||||
}
|
||||
|
||||
private fun parsePosition(json: ObjectNode, conn: WebSocket) {
|
||||
if (json["tracker_id"].asInt() == 0) {
|
||||
// Read HMD information
|
||||
internalHMDTracker
|
||||
.position = Vector3(
|
||||
json["x"].asDouble().toFloat(),
|
||||
json["y"].asDouble().toFloat() + 0.2f,
|
||||
json["z"].asDouble().toFloat(),
|
||||
private fun parsePosition(jsonObj: JsonObject, conn: WebSocket) {
|
||||
// HMD usually sends tracker_id as 0 (number)
|
||||
val trackerId = jsonObj["tracker_id"]?.jsonPrimitive?.intOrNull ?: -1
|
||||
|
||||
if (trackerId == 0) {
|
||||
internalHMDTracker.position = Vector3(
|
||||
jsonObj["x"]?.jsonPrimitive?.float ?: 0f,
|
||||
(jsonObj["y"]?.jsonPrimitive?.float ?: 0f) + 0.2f,
|
||||
jsonObj["z"]?.jsonPrimitive?.float ?: 0f,
|
||||
)
|
||||
internalHMDTracker.setRotation(
|
||||
Quaternion(
|
||||
jsonObj["qw"]?.jsonPrimitive?.float ?: 1f,
|
||||
jsonObj["qx"]?.jsonPrimitive?.float ?: 0f,
|
||||
jsonObj["qy"]?.jsonPrimitive?.float ?: 0f,
|
||||
jsonObj["qz"]?.jsonPrimitive?.float ?: 0f,
|
||||
),
|
||||
)
|
||||
// TODO Wtf is this hack? VRWorkout issue?
|
||||
internalHMDTracker
|
||||
.setRotation(
|
||||
Quaternion(
|
||||
json["qw"].asDouble().toFloat(),
|
||||
json["qx"].asDouble().toFloat(),
|
||||
json["qy"].asDouble().toFloat(),
|
||||
json["qz"].asDouble().toFloat(),
|
||||
),
|
||||
)
|
||||
internalHMDTracker.dataTick()
|
||||
newHMDData.set(true)
|
||||
|
||||
// Send tracker info in reply
|
||||
for (i in internalTrackers.indices) {
|
||||
val message = mapper.nodeFactory.objectNode()
|
||||
message.put("type", "pos")
|
||||
message.put("src", "full")
|
||||
message.put("tracker_id", "SlimeVR Tracker ${i + 1}")
|
||||
|
||||
val t = internalTrackers[i]
|
||||
message.put("x", t.position.x)
|
||||
message.put("y", t.position.y)
|
||||
message.put("z", t.position.z)
|
||||
message.put("qx", t.getRotation().x)
|
||||
message.put("qy", t.getRotation().y)
|
||||
message.put("qz", t.getRotation().z)
|
||||
message.put("qw", t.getRotation().w)
|
||||
|
||||
conn.send(message.toString())
|
||||
val rot = t.getRotation()
|
||||
val reply = OutgoingPositionMessage(
|
||||
trackerId = "SlimeVR Tracker ${i + 1}",
|
||||
x = t.position.x,
|
||||
y = t.position.y,
|
||||
z = t.position.z,
|
||||
qx = rot.x,
|
||||
qy = rot.y,
|
||||
qz = rot.z,
|
||||
qw = rot.w,
|
||||
)
|
||||
conn.send(json.encodeToString(reply))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun parseAction(json: ObjectNode, conn: WebSocket) {
|
||||
when (json["name"].asText()) {
|
||||
private fun parseAction(jsonObj: JsonObject) {
|
||||
val action = json.decodeFromJsonElement<IncomingActionMessage>(jsonObj)
|
||||
when (action.name) {
|
||||
"calibrate" -> instance.resetTrackersYaw(RESET_SOURCE_NAME)
|
||||
"full_calibrate" -> instance.resetTrackersFull(RESET_SOURCE_NAME)
|
||||
"mounting_calibrate" -> instance.resetTrackersMounting(RESET_SOURCE_NAME)
|
||||
@@ -213,25 +221,13 @@ class WebSocketVRBridge(
|
||||
|
||||
override fun onStart() {
|
||||
LogManager.info("[WebSocket] Web Socket VR Bridge started on port $port")
|
||||
connectionLostTimeout = 0
|
||||
connectionLostTimeout = 1
|
||||
// This has to be removed for Android
|
||||
// (keepalive did not work for me @mgschwan)
|
||||
}
|
||||
|
||||
override fun addSharedTracker(tracker: Tracker?) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
override fun removeSharedTracker(tracker: Tracker?) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
override fun startBridge() {
|
||||
start()
|
||||
}
|
||||
|
||||
override fun isConnected(): Boolean = super.getConnections().isNotEmpty()
|
||||
override fun addSharedTracker(tracker: Tracker?) {}
|
||||
override fun removeSharedTracker(tracker: Tracker?) {}
|
||||
override fun startBridge() = start()
|
||||
override fun isConnected(): Boolean = connections.isNotEmpty()
|
||||
|
||||
companion object {
|
||||
private const val RESET_SOURCE_NAME = "WebSocketVRBridge"
|
||||
|
||||
@@ -6,7 +6,6 @@ import dev.slimevr.Keybinding
|
||||
import dev.slimevr.SLIMEVR_IDENTIFIER
|
||||
import dev.slimevr.VRServer
|
||||
import dev.slimevr.bridge.Bridge
|
||||
import dev.slimevr.config.ConfigManager
|
||||
import dev.slimevr.desktop.firmware.DesktopSerialFlashingHandler
|
||||
import dev.slimevr.desktop.games.vrchat.DesktopVRCConfigHandler
|
||||
import dev.slimevr.desktop.platform.SteamVRBridge
|
||||
@@ -102,14 +101,14 @@ fun main(args: Array<String>) {
|
||||
val configDir = resolveConfig()
|
||||
LogManager.info("Using config dir: $configDir")
|
||||
|
||||
val configManager = ConfigManager(configDir)
|
||||
configManager.loadConfig()
|
||||
val configProfileHandler = ConfigProfileHandler(configDir)
|
||||
configProfileHandler.loadConfig()
|
||||
|
||||
try {
|
||||
DatagramSocket(configManager.vrConfig.server.trackerPort).close()
|
||||
DatagramSocket(configProfileHandler.vrConfig.server.trackerPort).close()
|
||||
ServerSocket(21110).close()
|
||||
} catch (e: IOException) {
|
||||
val message = "SlimeVR start-up error! A required port (${configManager.vrConfig.server.trackerPort} and 21110) is busy. " +
|
||||
val message = "SlimeVR start-up error! A required port (${configProfileHandler.vrConfig.server.trackerPort} and 21110) is busy. " +
|
||||
"Make sure there is no other instance of SlimeVR Server running."
|
||||
LogManager
|
||||
.severe(message)
|
||||
@@ -130,7 +129,7 @@ fun main(args: Array<String>) {
|
||||
{ _ -> DesktopSerialFlashingHandler() },
|
||||
{ _ -> DesktopVRCConfigHandler() },
|
||||
{ server -> DesktopNetworkProfileChecker(server) },
|
||||
configManager = configManager,
|
||||
configManager = configProfileHandler,
|
||||
)
|
||||
vrServer.start()
|
||||
|
||||
|
||||
@@ -25,13 +25,14 @@ abstract class SteamVRBridge(
|
||||
) : ProtobufBridge(bridgeName),
|
||||
Runnable {
|
||||
protected val runnerThread: Thread = Thread(this, threadName)
|
||||
protected val config: BridgeConfig = server.configManager.vrConfig.getBridge(bridgeSettingsKey)
|
||||
// protected val config: BridgeConfig?
|
||||
// get() = server.configManager.settings.get().bridges[bridgeSettingsKey]
|
||||
var connected: Boolean = false
|
||||
|
||||
@VRServerThread
|
||||
override fun startBridge() {
|
||||
for (tr in shareableTrackers) {
|
||||
val role = tr.trackerPosition?.trackerRole
|
||||
val role = tr.trackerPosition?.trackerRole ?: error("invalid state")
|
||||
changeShareSettings(
|
||||
role,
|
||||
config.getBridgeTrackerRole(role, false),
|
||||
|
||||
+1
-2
@@ -1,7 +1,6 @@
|
||||
package dev.slimevr.desktop.tracking.trackers.hid
|
||||
|
||||
import dev.slimevr.VRServer
|
||||
import dev.slimevr.config.config
|
||||
import dev.slimevr.tracking.trackers.Device
|
||||
import dev.slimevr.tracking.trackers.Tracker
|
||||
import dev.slimevr.tracking.trackers.TrackerStatus
|
||||
@@ -213,7 +212,7 @@ class DesktopHIDManager(name: String, private val trackersConsumer: Consumer<Tra
|
||||
private fun deviceEnumerate() {
|
||||
var rootReceivers: HidDeviceInfoStructure? = null
|
||||
var rootTrackers: HidDeviceInfoStructure? = null
|
||||
val trackersOverHID: Boolean = VRServer.instance.configManager.vrConfig.hidConfig.trackersOverHID
|
||||
val trackersOverHID: Boolean = VRServer.instance.configManager.settings.get().hidConfig.trackersOverHID
|
||||
try {
|
||||
rootReceivers = HidApi.enumerateDevices(HID_TRACKER_RECEIVER_VID, HID_TRACKER_RECEIVER_PID) // TODO: Use list of ids
|
||||
rootTrackers = if (trackersOverHID) {
|
||||
|
||||
Reference in new issue
Block a user