Disable leg tweaks on proportions (#627)

This commit is contained in:
Collin Kees
2023-03-25 14:41:10 -07:00
committed by GitHub
parent 56d47996f0
commit ab425f41cd
8 changed files with 160 additions and 26 deletions

View File

@@ -1,6 +1,8 @@
import classNames from 'classnames';
import { ReactNode, useEffect, useState } from 'react';
import {
LegTweaksTmpChangeT,
LegTweaksTmpClearT,
ResetType,
RpcMessage,
SettingsRequestT,
@@ -32,6 +34,7 @@ export function MainLayoutRoute({
const { useRPCPacket, sendRPCPacket } = useWebsocketAPI();
const [driftCompensationEnabled, setDriftCompensationEnabled] =
useState(false);
const [ProportionsLastPageOpen, setProportionsLastPageOpen] = useState(true);
useEffect(() => {
sendRPCPacket(RpcMessage.SettingsRequest, new SettingsRequestT());
@@ -42,6 +45,33 @@ export function MainLayoutRoute({
setDriftCompensationEnabled(settings.driftCompensation.enabled);
});
function usePageChanged(callback: () => void) {
useEffect(() => {
callback();
}, [location.pathname]);
}
usePageChanged(() => {
if (location.pathname.includes('body-proportions')) {
const tempSettings = new LegTweaksTmpChangeT();
tempSettings.skatingCorrection = false;
tempSettings.floorClip = false;
tempSettings.toeSnap = false;
tempSettings.footPlant = false;
sendRPCPacket(RpcMessage.LegTweaksTmpChange, tempSettings);
} else if (ProportionsLastPageOpen) {
const resetSettings = new LegTweaksTmpClearT();
resetSettings.skatingCorrection = true;
resetSettings.floorClip = true;
resetSettings.toeSnap = true;
resetSettings.footPlant = true;
sendRPCPacket(RpcMessage.LegTweaksTmpClear, resetSettings);
}
setProportionsLastPageOpen(location.pathname.includes('body-proportions'));
});
return (
<>
<TopBar></TopBar>

View File

@@ -159,7 +159,6 @@ export function GeneralSettings() {
const modelSettings = new ModelSettingsT();
const toggles = new ModelTogglesT();
const legTweaks = new LegTweaksSettingsT();
toggles.floorClip = values.toggles.floorClip;
toggles.skatingCorrection = values.toggles.skatingCorrection;
toggles.extendedKnee = values.toggles.extendedKnee;
@@ -169,6 +168,8 @@ export function GeneralSettings() {
toggles.viveEmulation = values.toggles.viveEmulation;
toggles.toeSnap = values.toggles.toeSnap;
toggles.footPlant = values.toggles.footPlant;
const legTweaks = new LegTweaksSettingsT();
legTweaks.correctionStrength = values.legTweaks.correctionStrength;
modelSettings.toggles = toggles;

12
package-lock.json generated
View File

@@ -9325,9 +9325,9 @@
}
},
"node_modules/webpack": {
"version": "5.75.0",
"resolved": "https://registry.npmjs.org/webpack/-/webpack-5.75.0.tgz",
"integrity": "sha512-piaIaoVJlqMsPtX/+3KTTO6jfvrSYgauFVdt8cr9LTHKmcq/AMd4mhzsiP7ZF/PGRNPGA8336jldh9l2Kt2ogQ==",
"version": "5.76.2",
"resolved": "https://registry.npmjs.org/webpack/-/webpack-5.76.2.tgz",
"integrity": "sha512-Th05ggRm23rVzEOlX8y67NkYCHa9nTNcwHPBhdg+lKG+mtiW7XgggjAeeLnADAe7mLjJ6LUNfgHAuRRh+Z6J7w==",
"peer": true,
"dependencies": {
"@types/eslint-scope": "^3.7.3",
@@ -15881,9 +15881,9 @@
}
},
"webpack": {
"version": "5.75.0",
"resolved": "https://registry.npmjs.org/webpack/-/webpack-5.75.0.tgz",
"integrity": "sha512-piaIaoVJlqMsPtX/+3KTTO6jfvrSYgauFVdt8cr9LTHKmcq/AMd4mhzsiP7ZF/PGRNPGA8336jldh9l2Kt2ogQ==",
"version": "5.76.2",
"resolved": "https://registry.npmjs.org/webpack/-/webpack-5.76.2.tgz",
"integrity": "sha512-Th05ggRm23rVzEOlX8y67NkYCHa9nTNcwHPBhdg+lKG+mtiW7XgggjAeeLnADAe7mLjJ6LUNfgHAuRRh+Z6J7w==",
"peer": true,
"requires": {
"@types/eslint-scope": "^3.7.3",

View File

@@ -78,6 +78,10 @@ public class RPCHandler extends ProtocolHandler<RpcMessageHeader>
registerPacketListener(RpcMessage.ServerInfosRequest, this::onServerInfosRequest);
registerPacketListener(RpcMessage.LegTweaksTmpChange, this::onLegTweaksTmpChange);
registerPacketListener(RpcMessage.LegTweaksTmpClear, this::onLegTweaksTmpClear);
this.api.server.getAutoBoneHandler().addListener(this);
}
@@ -259,6 +263,43 @@ public class RPCHandler extends ProtocolHandler<RpcMessageHeader>
this.api.server.clearTrackersDriftCompensation();
}
public void onLegTweaksTmpChange(
GenericConnection conn,
RpcMessageHeader messageHeader
) {
LegTweaksTmpChange req = (LegTweaksTmpChange) messageHeader
.message(new LegTweaksTmpChange());
if (req == null)
return;
this.api.server.humanPoseManager
.setLegTweaksStateTemp(
req.skatingCorrection(),
req.floorClip(),
req.toeSnap(),
req.footPlant()
);
}
public void onLegTweaksTmpClear(
GenericConnection conn,
RpcMessageHeader messageHeader
) {
LegTweaksTmpClear req = (LegTweaksTmpClear) messageHeader
.message(new LegTweaksTmpClear());
if (req == null)
return;
this.api.server.humanPoseManager
.clearLegTweaksStateTemp(
req.skatingCorrection(),
req.floorClip(),
req.toeSnap(),
req.footPlant()
);
}
@Override
public void onMessage(GenericConnection conn, RpcMessageHeader message) {
BiConsumer<GenericConnection, RpcMessageHeader> consumer = this.handlers[message

View File

@@ -601,6 +601,26 @@ public class HumanPoseManager {
}
}
public void setLegTweaksStateTemp(
boolean skatingCorrection,
boolean floorClip,
boolean toeSnap,
boolean footPlant
) {
if (isSkeletonPresent())
skeleton.setLegTweaksStateTemp(skatingCorrection, floorClip, toeSnap, footPlant);
}
public void clearLegTweaksStateTemp(
boolean skatingCorrection,
boolean floorClip,
boolean toeSnap,
boolean footPlant
) {
if (isSkeletonPresent())
skeleton.clearLegTweaksStateTemp(skatingCorrection, floorClip, toeSnap, footPlant);
}
public void updateTapDetectionConfig() {
if (isSkeletonPresent())
skeleton.updateTapDetectionConfig();

View File

@@ -1240,8 +1240,8 @@ public class HumanSkeleton {
case SKATING_CORRECTION -> legTweaks.setSkatingReductionEnabled(newValue);
case FLOOR_CLIP -> legTweaks.setFloorclipEnabled(newValue);
case VIVE_EMULATION -> viveEmulation.setEnabled(newValue);
case TOE_SNAP -> legTweaks.setToeSnap(newValue);
case FOOT_PLANT -> legTweaks.setFootPlant(newValue);
case TOE_SNAP -> legTweaks.setToeSnapEnabled(newValue);
case FOOT_PLANT -> legTweaks.setFootPlantEnabled(newValue);
}
}
@@ -1710,10 +1710,50 @@ public class HumanSkeleton {
legTweaks.updateConfig();
}
// does not save to config
public void setLegTweaksStateTemp(
boolean skatingCorrection,
boolean floorClip,
boolean toeSnap,
boolean footPlant
) {
this.legTweaks.setSkatingReductionEnabled(skatingCorrection);
this.legTweaks.setFloorclipEnabled(floorClip);
this.legTweaks.setToeSnapEnabled(toeSnap);
this.legTweaks.setFootPlantEnabled(footPlant);
}
// resets to config values
public void clearLegTweaksStateTemp(
boolean skatingCorrection,
boolean floorClip,
boolean toeSnap,
boolean footPlant
) {
// only reset the true values as they are a mask for what to reset
if (skatingCorrection)
this.legTweaks
.setSkatingReductionEnabled(
humanPoseManager.getToggle(SkeletonConfigToggles.SKATING_CORRECTION)
);
if (floorClip)
this.legTweaks
.setFloorclipEnabled(humanPoseManager.getToggle(SkeletonConfigToggles.FLOOR_CLIP));
if (toeSnap)
this.legTweaks
.setToeSnapEnabled(humanPoseManager.getToggle(SkeletonConfigToggles.TOE_SNAP));
if (footPlant)
this.legTweaks
.setFootPlantEnabled(humanPoseManager.getToggle(SkeletonConfigToggles.FOOT_PLANT));
}
public boolean[] getLegTweaksState() {
boolean[] state = new boolean[2];
boolean[] state = new boolean[4];
state[0] = this.legTweaks.getFloorclipEnabled();
state[1] = this.legTweaks.getSkatingReductionEnabled();
state[2] = this.legTweaks.getToeSnapEnabled();
state[3] = this.legTweaks.getFootPlantEnabled();
return state;
}

View File

@@ -77,8 +77,8 @@ public class LegTweaks {
private boolean enabled = true; // master switch
private boolean floorclipEnabled = false;
private boolean skatingCorrectionEnabled = false;
private boolean toeSnap = false;
private boolean footPlant = false;
private boolean toeSnapEnabled = false;
private boolean footPlantEnabled = false;
private boolean active = false;
private boolean rightLegActive = false;
private boolean leftLegActive = false;
@@ -213,12 +213,12 @@ public class LegTweaks {
this.bufferInvalid = true;
}
public void setToeSnap(boolean val) {
this.toeSnap = val;
public void setToeSnapEnabled(boolean val) {
this.toeSnapEnabled = val;
}
public void setFootPlant(boolean val) {
this.footPlant = val;
public void setFootPlantEnabled(boolean val) {
this.footPlantEnabled = val;
}
public boolean getEnabled() {
@@ -233,12 +233,12 @@ public class LegTweaks {
return this.skatingCorrectionEnabled;
}
public boolean getToeSnap() {
return this.toeSnap;
public boolean getToeSnapEnabled() {
return this.toeSnapEnabled;
}
public boolean getFootPlant() {
return this.footPlant;
public boolean getFootPlantEnabled() {
return this.footPlantEnabled;
}
public void resetBuffer() {
@@ -256,8 +256,8 @@ public class LegTweaks {
floorclipEnabled = skeleton.humanPoseManager.getToggle(SkeletonConfigToggles.FLOOR_CLIP);
skatingCorrectionEnabled = skeleton.humanPoseManager
.getToggle(SkeletonConfigToggles.SKATING_CORRECTION);
toeSnap = skeleton.humanPoseManager.getToggle(SkeletonConfigToggles.TOE_SNAP);
footPlant = skeleton.humanPoseManager.getToggle(SkeletonConfigToggles.FOOT_PLANT);
toeSnapEnabled = skeleton.humanPoseManager.getToggle(SkeletonConfigToggles.TOE_SNAP);
footPlantEnabled = skeleton.humanPoseManager.getToggle(SkeletonConfigToggles.FOOT_PLANT);
}
// update the hyperparameters with the config
@@ -344,8 +344,10 @@ public class LegTweaks {
footLength = skeleton.leftFootNode.localTransform.getTranslation().length();
// if not enabled, do nothing and return false
if (!enabled)
if (!enabled) {
bufferInvalid = true;
return false;
}
// if the user is standing start checking for a good time to enable leg
// tweaks
@@ -778,7 +780,7 @@ public class LegTweaks {
float masterWeightR = getMasterWeight(kneeAngleR);
// corrects rotations when planted firmly on the ground
if (footPlant) {
if (footPlantEnabled) {
// prepare the weight vars for this correction step
float weightL = 0.0f;
float weightR = 0.0f;
@@ -812,7 +814,7 @@ public class LegTweaks {
// corrects rotations when the foot is in the air by rotating the foot
// down so that the toes are touching
if (toeSnap) {
if (toeSnapEnabled) {
// this correction step has its own weight vars
float weightL = 0.0f;
float weightR = 0.0f;