Skip to content

Commit

Permalink
Resets settings (#806)
Browse files Browse the repository at this point in the history
  • Loading branch information
Erimelowo authored Sep 2, 2023
1 parent 7231f46 commit bc5f9a1
Show file tree
Hide file tree
Showing 10 changed files with 355 additions and 96 deletions.
11 changes: 11 additions & 0 deletions gui/public/i18n/en/translation.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,20 @@ settings-general-fk_settings-leg_tweak-floor_clip-description = Floor-clip can R
settings-general-fk_settings-leg_tweak-toe_snap-description = Toe-snap attempts to guess the rotation of your feet if feet trackers are not in use.
settings-general-fk_settings-leg_tweak-foot_plant-description = Foot-plant rotates your feet to be parallel to the ground when in contact.
settings-general-fk_settings-leg_fk = Leg tracking
settings-general-fk_settings-leg_fk-reset_mounting_feet-description = Enable feet Mounting Reset by tiptoeing.
settings-general-fk_settings-leg_fk-reset_mounting_feet = Feet Mounting Reset
settings-general-fk_settings-arm_fk = Arm tracking
settings-general-fk_settings-arm_fk-description = Force arms to be tracked from the HMD even if positional hand data is available.
settings-general-fk_settings-arm_fk-force_arms = Force arms from HMD
settings-general-fk_settings-arm_fk-reset_mode-description = Change which arm pose is expected for mounting reset.
settings-general-fk_settings-arm_fk-back = Back
settings-general-fk_settings-arm_fk-back-description = The default mode, with the upper arms going back and lower arms going forward.
settings-general-fk_settings-arm_fk-tpose_up = T-pose (up)
settings-general-fk_settings-arm_fk-tpose_up-description = Expects your arms to be down on the sides during Full Reset, and 90 degrees up to the sides during Mounting Reset.
settings-general-fk_settings-arm_fk-tpose_down = T-pose (down)
settings-general-fk_settings-arm_fk-tpose_down-description = Expects your arms to be 90 degrees up to the sides during Full Reset, and down on the sides during Mounting Reset.
settings-general-fk_settings-arm_fk-forward = Forward
settings-general-fk_settings-arm_fk-forward-description = Expects your arms to be up 90 degrees forward. Useful for VTubing.
settings-general-fk_settings-skeleton_settings-toggles = Skeleton toggles
settings-general-fk_settings-skeleton_settings-description = Toggle skeleton settings on or off. It is recommended to leave these on.
settings-general-fk_settings-skeleton_settings-extended_spine_model = Extended spine model
Expand Down
94 changes: 93 additions & 1 deletion gui/src/components/settings/pages/GeneralSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ModelRatiosT,
ModelSettingsT,
ModelTogglesT,
ResetsSettingsT,
RpcMessage,
SettingsRequestT,
SettingsResponseT,
Expand Down Expand Up @@ -84,6 +85,10 @@ interface SettingsForm {
legTweaks: {
correctionStrength: number;
};
resetsSettings: {
resetMountingFeet: boolean;
armsMountingResetMode: number;
};
}

const defaultValues = {
Expand All @@ -104,7 +109,7 @@ const defaultValues = {
skatingCorrection: false,
viveEmulation: false,
toeSnap: false,
flootPlant: true,
footPlant: true,
selfLocalization: false,
},
ratios: {
Expand Down Expand Up @@ -135,6 +140,10 @@ const defaultValues = {
numberTrackersOverThreshold: 1,
},
legTweaks: { correctionStrength: 0.3 },
resetsSettings: {
resetMountingFeet: false,
armsMountingResetMode: 0,
},
};

export function GeneralSettings() {
Expand Down Expand Up @@ -237,6 +246,15 @@ export function GeneralSettings() {
driftCompensation.maxResets = values.driftCompensation.maxResets;
settings.driftCompensation = driftCompensation;

if (values.resetsSettings) {
const resetsSettings = new ResetsSettingsT();
resetsSettings.resetMountingFeet =
values.resetsSettings.resetMountingFeet;
resetsSettings.armsMountingResetMode =
values.resetsSettings.armsMountingResetMode;
settings.resetsSettings = resetsSettings;
}

sendRPCPacket(RpcMessage.ChangeSettingsRequest, settings);
};

Expand Down Expand Up @@ -333,6 +351,10 @@ export function GeneralSettings() {
};
}

if (settings.resetsSettings) {
formData.resetsSettings = settings.resetsSettings;
}

reset(formData);
});

Expand Down Expand Up @@ -654,6 +676,24 @@ export function GeneralSettings() {
)}
/>
</div>
<div className="flex flex-col pt-2 pb-3">
<Typography color="secondary">
{l10n.getString(
'settings-general-fk_settings-leg_fk-reset_mounting_feet-description'
)}
</Typography>
</div>
<div className="grid sm:grid-cols-1 gap-3 pb-3">
<CheckBox
variant="toggle"
outlined
control={control}
name="resetsSettings.resetMountingFeet"
label={l10n.getString(
'settings-general-fk_settings-leg_fk-reset_mounting_feet'
)}
/>
</div>

<div className="flex flex-col pt-2 pb-3">
<Typography bold>
Expand All @@ -676,6 +716,58 @@ export function GeneralSettings() {
)}
/>
</div>

<Typography color="secondary">
{l10n.getString(
'settings-general-fk_settings-arm_fk-reset_mode-description'
)}
</Typography>
<div className="grid md:grid-cols-2 flex-col gap-3 pt-2">
<Radio
control={control}
name="resetsSettings.armsMountingResetMode"
label={l10n.getString(
'settings-general-fk_settings-arm_fk-back'
)}
desciption={l10n.getString(
'settings-general-fk_settings-arm_fk-back-description'
)}
value={0}
></Radio>
<Radio
control={control}
name="resetsSettings.armsMountingResetMode"
label={l10n.getString(
'settings-general-fk_settings-arm_fk-forward'
)}
desciption={l10n.getString(
'settings-general-fk_settings-arm_fk-forward-description'
)}
value={1}
></Radio>
<Radio
control={control}
name="resetsSettings.armsMountingResetMode"
label={l10n.getString(
'settings-general-fk_settings-arm_fk-tpose_up'
)}
desciption={l10n.getString(
'settings-general-fk_settings-arm_fk-tpose_up-description'
)}
value={2}
></Radio>
<Radio
control={control}
name="resetsSettings.armsMountingResetMode"
label={l10n.getString(
'settings-general-fk_settings-arm_fk-tpose_down'
)}
desciption={l10n.getString(
'settings-general-fk_settings-arm_fk-tpose_down-description'
)}
value={3}
></Radio>
</div>
{config?.debug && (
<>
<div className="flex flex-col pt-2 pb-3">
Expand Down
47 changes: 47 additions & 0 deletions server/core/src/main/java/dev/slimevr/config/ResetsConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package dev.slimevr.config

import dev.slimevr.VRServer

enum class ArmsResetModes(val id: Int) {
// Upper arm going back and forearm going forward
BACK(0),

// Arms going forward
FORWARD(1),

// Arms going up to the sides into a tpose
TPOSE_UP(2),

// Arms going down to the sides from a tpose
TPOSE_DOWN(3),
;

companion object {
val values = entries.toTypedArray()

@JvmStatic
fun fromId(id: Int): ArmsResetModes? {
for (filter in values) {
if (filter.id == id) return filter
}
return null
}
}
}

class ResetsConfig {

// Enable mounting reset for feet?
var resetMountingFeet = false

// Reset mode used for the arms
var mode = ArmsResetModes.BACK

fun updateTrackersResetsSettings() {
for (t in VRServer.instance.allTrackers) {
if (t.needsReset) {
t.resetsHandler.readArmsResetModeConfig(this)
}
}
}
}
8 changes: 8 additions & 0 deletions server/core/src/main/java/dev/slimevr/config/VRConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class VRConfig {

private final TapDetectionConfig tapDetection = new TapDetectionConfig();

private final ResetsConfig resetsConfig = new ResetsConfig();

@JsonDeserialize(using = TrackerConfigMapDeserializer.class)
@JsonSerialize(keyUsing = StdKeySerializers.StringKeySerializer.class)
private final Map<String, TrackerConfig> trackers = new HashMap<>();
Expand Down Expand Up @@ -132,6 +134,10 @@ public TapDetectionConfig getTapDetection() {
return tapDetection;
}

public ResetsConfig getResetsConfig() {
return resetsConfig;
}

public OverlayConfig getOverlay() {
return overlay;
}
Expand All @@ -151,6 +157,8 @@ public void readTrackerConfig(Tracker tracker) {
tracker.readConfig(config);
if (tracker.isImu())
tracker.getResetsHandler().readDriftCompensationConfig(driftCompensation);
if (tracker.getNeedsReset())
tracker.getResetsHandler().readArmsResetModeConfig(resetsConfig);
if (tracker.getAllowFiltering())
tracker
.getFilteringHandler()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,16 @@ public static AutoBoneConfig readAutoBoneSettings(

return autoBoneConfig;
}

public static int createArmsResetModeSettings(
FlatBufferBuilder fbb,
ResetsConfig resetsConfig
) {
return ResetsSettings
.createResetsSettings(
fbb,
resetsConfig.getResetMountingFeet(),
resetsConfig.getMode().getId()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
import dev.slimevr.tracking.processor.config.SkeletonConfigToggles;
import dev.slimevr.tracking.processor.config.SkeletonConfigValues;
import dev.slimevr.tracking.trackers.TrackerRole;
import solarxr_protocol.rpc.ChangeSettingsRequest;
import solarxr_protocol.rpc.RpcMessage;
import solarxr_protocol.rpc.RpcMessageHeader;
import solarxr_protocol.rpc.SettingsResponse;
import solarxr_protocol.rpc.*;


public class RPCSettingsHandler {
Expand Down Expand Up @@ -85,6 +82,11 @@ public void onSettingsRequest(GenericConnection conn, RpcMessageHeader messageHe
.createAutoBoneSettings(
fbb,
this.api.server.configManager.getVrConfig().getAutoBone()
),
RPCSettingsBuilder
.createArmsResetModeSettings(
fbb,
this.api.server.configManager.getVrConfig().getResetsConfig()
)
);
int outbound = rpcHandler.createRPCMessage(fbb, RpcMessage.SettingsResponse, settings);
Expand Down Expand Up @@ -383,6 +385,19 @@ public void onChangeSettingsRequest(GenericConnection conn, RpcMessageHeader mes
RPCSettingsBuilder.readAutoBoneSettings(autoBoneSettings, autoBoneConfig);
}

if (req.resetsSettings() != null) {
ResetsConfig resetsConfig = this.api.server.configManager
.getVrConfig()
.getResetsConfig();
ArmsResetModes mode = ArmsResetModes
.fromId(Math.max(req.resetsSettings().armsMountingResetMode(), 0));
if (mode != null) {
resetsConfig.setMode(mode);
}
resetsConfig.setResetMountingFeet(req.resetsSettings().resetMountingFeet());
resetsConfig.updateTrackersResetsSettings();
}

this.api.server.configManager.saveConfig();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public enum SkeletonConfigOffsets {
SHOULDERS_WIDTH(
15,
"shouldersWidth",
0.36f,
0.35f,
new BoneType[] { BoneType.LEFT_SHOULDER, BoneType.RIGHT_SHOULDER }
),
UPPER_ARM(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1234,25 +1234,6 @@ class HumanSkeleton(
LogManager.info(String.format("[HumanSkeleton] Reset: yaw (%s)", resetSourceName))
}

private fun shouldResetMounting(position: TrackerPosition?): Boolean {
return position != null && position !== TrackerPosition.LEFT_FOOT && position !== TrackerPosition.RIGHT_FOOT
}

private fun shouldResetMounting(tracker: Tracker): Boolean {
return shouldResetMounting(tracker.trackerPosition)
}

private fun shouldReverseYaw(position: TrackerPosition?): Boolean {
return when (position) {
TrackerPosition.LEFT_UPPER_LEG, TrackerPosition.RIGHT_UPPER_LEG, TrackerPosition.LEFT_LOWER_ARM, TrackerPosition.LEFT_HAND, TrackerPosition.RIGHT_LOWER_ARM, TrackerPosition.RIGHT_HAND -> true
else -> false
}
}

private fun shouldReverseYaw(tracker: Tracker): Boolean {
return shouldReverseYaw(tracker.trackerPosition)
}

@VRServerThread
fun resetTrackersMounting(resetSourceName: String?) {
val trackersToReset = humanPoseManager.getTrackersToReset()
Expand All @@ -1262,21 +1243,15 @@ class HumanSkeleton(
var referenceRotation = IDENTITY
if (headTracker != null) {
if (headTracker!!.needsMounting) {
headTracker!!
.resetsHandler
.resetMounting(shouldReverseYaw(headTracker!!), referenceRotation)
headTracker!!.resetsHandler.resetMounting(referenceRotation)
} else {
referenceRotation =
headTracker!!.getRotation()
}
}
for (tracker in trackersToReset) {
if (tracker != null && tracker.needsMounting &&
shouldResetMounting(tracker)
) {
tracker
.resetsHandler
.resetMounting(shouldReverseYaw(tracker), referenceRotation)
if (tracker != null && tracker.needsMounting) {
tracker.resetsHandler.resetMounting(referenceRotation)
}
}
legTweaks.resetBuffer()
Expand Down
Loading

0 comments on commit bc5f9a1

Please sign in to comment.