mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-20 09:01:20 -08:00
Remove String skeleton config & fix null exception with SkeletonConfig
This commit is contained in:
5 files changed
+89
-117
No files matched your search
@@ -11,6 +11,7 @@ import javax.swing.event.MouseInputAdapter;
|
||||
import dev.slimevr.gui.swing.ButtonTimer;
|
||||
import dev.slimevr.gui.swing.EJBagNoStretch;
|
||||
import dev.slimevr.vr.processor.skeleton.HumanSkeleton;
|
||||
import dev.slimevr.vr.processor.skeleton.SkeletonConfigValue;
|
||||
import io.eiren.util.StringUtils;
|
||||
import io.eiren.util.ann.ThreadSafe;
|
||||
import io.eiren.vr.VRServer;
|
||||
@@ -20,7 +21,7 @@ public class SkeletonConfigGUI extends EJBagNoStretch {
|
||||
private final VRServer server;
|
||||
private final VRServerGUI gui;
|
||||
private final AutoBoneWindow autoBone;
|
||||
private Map<String, SkeletonLabel> labels = new HashMap<>();
|
||||
private Map<SkeletonConfigValue, SkeletonLabel> labels = new HashMap<>();
|
||||
|
||||
public SkeletonConfigGUI(VRServer server, VRServerGUI gui) {
|
||||
super(false, true);
|
||||
@@ -91,7 +92,7 @@ public class SkeletonConfigGUI extends EJBagNoStretch {
|
||||
row++;
|
||||
//*/
|
||||
|
||||
add(new TimedResetButton("Reset All", "All"), s(c(1, row, 2), 3, 1));
|
||||
add(new TimedResetButton("Reset All"), s(c(1, row, 2), 3, 1));
|
||||
add(new JButton("Auto") {{
|
||||
addMouseListener(new MouseInputAdapter() {
|
||||
@Override
|
||||
@@ -103,82 +104,14 @@ public class SkeletonConfigGUI extends EJBagNoStretch {
|
||||
}}, s(c(4, row, 2), 3, 1));
|
||||
row++;
|
||||
|
||||
add(new JLabel("Torso length"), c(0, row, 2));
|
||||
add(new AdjButton("+", "Torso", 0.01f), c(1, row, 2));
|
||||
add(new SkeletonLabel("Torso"), c(2, row, 2));
|
||||
add(new AdjButton("-", "Torso", -0.01f), c(3, row, 2));
|
||||
add(new TimedResetButton("Reset", "Torso"), c(4, row, 2));
|
||||
row++;
|
||||
|
||||
add(new JLabel("Chest distance"), c(0, row, 2));
|
||||
add(new AdjButton("+", "Chest", 0.01f), c(1, row, 2));
|
||||
add(new SkeletonLabel("Chest"), c(2, row, 2));
|
||||
add(new AdjButton("-", "Chest", -0.01f), c(3, row, 2));
|
||||
add(new ResetButton("Reset", "Chest"), c(4, row, 2));
|
||||
row++;
|
||||
|
||||
add(new JLabel("Waist distance"), c(0, row, 2));
|
||||
add(new AdjButton("+", "Waist", 0.01f), c(1, row, 2));
|
||||
add(new SkeletonLabel("Waist"), c(2, row, 2));
|
||||
add(new AdjButton("-", "Waist", -0.01f), c(3, row, 2));
|
||||
add(new ResetButton("Reset", "Waist"), c(4, row, 2));
|
||||
row++;
|
||||
|
||||
add(new JLabel("Hips width"), c(0, row, 2));
|
||||
add(new AdjButton("+", "Hips width", 0.01f), c(1, row, 2));
|
||||
add(new SkeletonLabel("Hips width"), c(2, row, 2));
|
||||
add(new AdjButton("-", "Hips width", -0.01f), c(3, row, 2));
|
||||
add(new ResetButton("Reset", "Hips width"), c(4, row, 2));
|
||||
row++;
|
||||
|
||||
add(new JLabel("Legs length"), c(0, row, 2));
|
||||
add(new AdjButton("+", "Legs length", 0.01f), c(1, row, 2));
|
||||
add(new SkeletonLabel("Legs length"), c(2, row, 2));
|
||||
add(new AdjButton("-", "Legs length", -0.01f), c(3, row, 2));
|
||||
add(new TimedResetButton("Reset", "Legs length"), c(4, row, 2));
|
||||
row++;
|
||||
|
||||
add(new JLabel("Knee height"), c(0, row, 2));
|
||||
add(new AdjButton("+", "Knee height", 0.01f), c(1, row, 2));
|
||||
add(new SkeletonLabel("Knee height"), c(2, row, 2));
|
||||
add(new AdjButton("-", "Knee height", -0.01f), c(3, row, 2));
|
||||
add(new ResetButton("Reset", "Knee height"), c(4, row, 2));
|
||||
row++;
|
||||
|
||||
add(new JLabel("Foot length"), c(0, row, 2));
|
||||
add(new AdjButton("+", "Foot length", 0.01f), c(1, row, 2));
|
||||
add(new SkeletonLabel("Foot length"), c(2, row, 2));
|
||||
add(new AdjButton("-", "Foot length", -0.01f), c(3, row, 2));
|
||||
add(new ResetButton("Reset", "Foot length"), c(4, row, 2));
|
||||
row++;
|
||||
|
||||
add(new JLabel("Head offset"), c(0, row, 2));
|
||||
add(new AdjButton("+", "Head", 0.01f), c(1, row, 2));
|
||||
add(new SkeletonLabel("Head"), c(2, row, 2));
|
||||
add(new AdjButton("-", "Head", -0.01f), c(3, row, 2));
|
||||
add(new ResetButton("Reset", "Head"), c(4, row, 2));
|
||||
row++;
|
||||
|
||||
add(new JLabel("Neck length"), c(0, row, 2));
|
||||
add(new AdjButton("+", "Neck", 0.01f), c(1, row, 2));
|
||||
add(new SkeletonLabel("Neck"), c(2, row, 2));
|
||||
add(new AdjButton("-", "Neck", -0.01f), c(3, row, 2));
|
||||
add(new ResetButton("Reset", "Neck"), c(4, row, 2));
|
||||
row++;
|
||||
|
||||
add(new JLabel("Hip offset"), c(0, row, 2));
|
||||
add(new AdjButton("+", "Hip offset", 0.01f), c(1, row, 2));
|
||||
add(new SkeletonLabel("Hip offset"), c(2, row, 2));
|
||||
add(new AdjButton("-", "Hip offset", -0.01f), c(3, row, 2));
|
||||
add(new ResetButton("Reset", "Hip offset"), c(4, row, 2));
|
||||
row++;
|
||||
|
||||
add(new JLabel("Foot offset"), c(0, row, 2));
|
||||
add(new AdjButton("+", "Foot offset", 0.01f), c(1, row, 2));
|
||||
add(new SkeletonLabel("Foot offset"), c(2, row, 2));
|
||||
add(new AdjButton("-", "Foot offset", -0.01f), c(3, row, 2));
|
||||
add(new ResetButton("Reset", "Foot offset"), c(4, row, 2));
|
||||
row++;
|
||||
for (SkeletonConfigValue config : SkeletonConfigValue.values) {
|
||||
add(new JLabel(config.label), c(0, row, 2));
|
||||
add(new AdjButton("+", config, 0.01f), c(1, row, 2));
|
||||
add(new SkeletonLabel(config), c(2, row, 2));
|
||||
add(new AdjButton("-", config, -0.01f), c(3, row, 2));
|
||||
add(new TimedResetButton("Reset", config), c(4, row, 2));
|
||||
row++;
|
||||
}
|
||||
|
||||
gui.refresh();
|
||||
});
|
||||
@@ -193,30 +126,31 @@ public class SkeletonConfigGUI extends EJBagNoStretch {
|
||||
});
|
||||
}
|
||||
|
||||
private void change(String joint, float diff) {
|
||||
private void change(SkeletonConfigValue joint, float diff) {
|
||||
float current = server.humanPoseProcessor.getSkeletonConfig(joint);
|
||||
server.humanPoseProcessor.setSkeletonConfig(joint, current + diff);
|
||||
server.saveConfig();
|
||||
labels.get(joint).setText(StringUtils.prettyNumber((current + diff) * 100, 0));
|
||||
}
|
||||
|
||||
private void reset(String joint) {
|
||||
private void reset(SkeletonConfigValue joint) {
|
||||
server.humanPoseProcessor.resetSkeletonConfig(joint);
|
||||
server.saveConfig();
|
||||
if(!"All".equals(joint)) {
|
||||
float current = server.humanPoseProcessor.getSkeletonConfig(joint);
|
||||
labels.get(joint).setText(StringUtils.prettyNumber((current) * 100, 0));
|
||||
} else {
|
||||
labels.forEach((jnt, label) -> {
|
||||
float current = server.humanPoseProcessor.getSkeletonConfig(jnt);
|
||||
label.setText(StringUtils.prettyNumber((current) * 100, 0));
|
||||
});
|
||||
}
|
||||
|
||||
float current = server.humanPoseProcessor.getSkeletonConfig(joint);
|
||||
labels.get(joint).setText(StringUtils.prettyNumber((current) * 100, 0));
|
||||
}
|
||||
|
||||
private void resetAll() {
|
||||
server.humanPoseProcessor.resetAllSkeletonConfigs();
|
||||
server.saveConfig();
|
||||
|
||||
refreshAll();
|
||||
}
|
||||
|
||||
private class SkeletonLabel extends JLabel {
|
||||
|
||||
public SkeletonLabel(String joint) {
|
||||
public SkeletonLabel(SkeletonConfigValue joint) {
|
||||
super(StringUtils.prettyNumber(server.humanPoseProcessor.getSkeletonConfig(joint) * 100, 0));
|
||||
labels.put(joint, this);
|
||||
}
|
||||
@@ -224,7 +158,7 @@ public class SkeletonConfigGUI extends EJBagNoStretch {
|
||||
|
||||
private class AdjButton extends JButton {
|
||||
|
||||
public AdjButton(String text, String joint, float diff) {
|
||||
public AdjButton(String text, SkeletonConfigValue joint, float diff) {
|
||||
super(text);
|
||||
addMouseListener(new MouseInputAdapter() {
|
||||
@Override
|
||||
@@ -237,7 +171,7 @@ public class SkeletonConfigGUI extends EJBagNoStretch {
|
||||
|
||||
private class ResetButton extends JButton {
|
||||
|
||||
public ResetButton(String text, String joint) {
|
||||
public ResetButton(String text, SkeletonConfigValue joint) {
|
||||
super(text);
|
||||
addMouseListener(new MouseInputAdapter() {
|
||||
@Override
|
||||
@@ -250,7 +184,7 @@ public class SkeletonConfigGUI extends EJBagNoStretch {
|
||||
|
||||
private class TimedResetButton extends JButton {
|
||||
|
||||
public TimedResetButton(String text, String joint) {
|
||||
public TimedResetButton(String text, SkeletonConfigValue joint) {
|
||||
super(text);
|
||||
addMouseListener(new MouseInputAdapter() {
|
||||
@Override
|
||||
@@ -259,5 +193,15 @@ public class SkeletonConfigGUI extends EJBagNoStretch {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public TimedResetButton(String text) {
|
||||
super(text);
|
||||
addMouseListener(new MouseInputAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
ButtonTimer.runTimer(TimedResetButton.this, 3, text, () -> resetAll());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,11 +20,6 @@ public abstract class HumanSkeleton {
|
||||
@ThreadSafe
|
||||
public abstract void resetSkeletonConfig(SkeletonConfigValue config);
|
||||
|
||||
@ThreadSafe
|
||||
public void resetSkeletonConfig(String config) {
|
||||
resetSkeletonConfig(SkeletonConfigValue.getByStringValue(config));
|
||||
}
|
||||
|
||||
@ThreadSafe
|
||||
public void resetAllSkeletonConfigs() {
|
||||
for (SkeletonConfigValue config : SkeletonConfigValue.values) {
|
||||
|
||||
@@ -92,7 +92,7 @@ public class SkeletonConfig {
|
||||
}
|
||||
|
||||
public Float setConfig(SkeletonConfigValue config, Float newValue) {
|
||||
Float origVal = configs.put(config, newValue);
|
||||
Float origVal = newValue != null ? configs.put(config, newValue) : configs.remove(config);
|
||||
|
||||
// Re-compute the affected offsets
|
||||
if (autoUpdateOffsets && config.affectedOffsets != null) {
|
||||
@@ -117,15 +117,24 @@ public class SkeletonConfig {
|
||||
}
|
||||
|
||||
public float getConfig(SkeletonConfigValue config) {
|
||||
return configs.getOrDefault(config, config.defaultValue);
|
||||
if (config == null) {
|
||||
return 0f;
|
||||
}
|
||||
|
||||
// IMPORTANT!! This null check is necessary, getOrDefault seems to randomly decide to return null at times, so this is a secondary check
|
||||
Float val = configs.getOrDefault(config, config.defaultValue);
|
||||
return val != null ? val : config.defaultValue;
|
||||
}
|
||||
|
||||
public float getConfig(String config) {
|
||||
if (config == null) {
|
||||
return 0f;
|
||||
}
|
||||
return getConfig(SkeletonConfigValue.getByStringValue(config));
|
||||
}
|
||||
|
||||
public Boolean setToggle(SkeletonConfigToggle config, Boolean newValue) {
|
||||
Boolean origVal = toggles.put(config, newValue);
|
||||
Boolean origVal = newValue != null ? toggles.put(config, newValue) : toggles.remove(config);
|
||||
|
||||
if (callback != null) {
|
||||
try {
|
||||
@@ -143,10 +152,20 @@ public class SkeletonConfig {
|
||||
}
|
||||
|
||||
public boolean getToggle(SkeletonConfigToggle config) {
|
||||
return toggles.getOrDefault(config, config.defaultValue);
|
||||
if (config == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// IMPORTANT!! This null check is necessary, getOrDefault seems to randomly decide to return null at times, so this is a secondary check
|
||||
Boolean val = toggles.getOrDefault(config, config.defaultValue);
|
||||
return val != null ? val : config.defaultValue;
|
||||
}
|
||||
|
||||
public boolean getToggle(String config) {
|
||||
if (config == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return getToggle(SkeletonConfigToggle.getByStringValue(config));
|
||||
}
|
||||
|
||||
@@ -170,6 +189,11 @@ public class SkeletonConfig {
|
||||
}
|
||||
|
||||
protected void setNodeOffset(SkeletonNodeOffset nodeOffset, Vector3f offset) {
|
||||
if (offset == null) {
|
||||
setNodeOffset(nodeOffset, 0f, 0f, 0f);
|
||||
return;
|
||||
}
|
||||
|
||||
setNodeOffset(nodeOffset, offset.x, offset.y, offset.z);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,23 +5,24 @@ import java.util.Map;
|
||||
|
||||
public enum SkeletonConfigValue {
|
||||
|
||||
HEAD("Head", "headShift", 0.1f, new SkeletonNodeOffset[] { SkeletonNodeOffset.HEAD }),
|
||||
NECK("Neck", "neckLength", 0.1f, new SkeletonNodeOffset[] { SkeletonNodeOffset.NECK }),
|
||||
TORSO("Torso", "torsoLength", 0.7f, new SkeletonNodeOffset[] { SkeletonNodeOffset.WAIST }),
|
||||
CHEST("Chest", "chestDistance", 0.35f, new SkeletonNodeOffset[] { SkeletonNodeOffset.CHEST, SkeletonNodeOffset.WAIST }),
|
||||
WAIST("Waist", "waistDistance", 0.1f, new SkeletonNodeOffset[] { SkeletonNodeOffset.WAIST, SkeletonNodeOffset.HIP }),
|
||||
HIP_OFFSET("Hip offset", "hipOffset", 0.0f, new SkeletonNodeOffset[] { SkeletonNodeOffset.HIP_TRACKER }),
|
||||
HIPS_WIDTH("Hips width", "hipsWidth", 0.3f, new SkeletonNodeOffset[] { SkeletonNodeOffset.LEFT_HIP, SkeletonNodeOffset.RIGHT_HIP }),
|
||||
LEGS_LENGTH("Legs length", "legsLength", 0.84f, new SkeletonNodeOffset[] { SkeletonNodeOffset.KNEE }),
|
||||
KNEE_HEIGHT("Knee height", "kneeHeight", 0.42f, new SkeletonNodeOffset[] { SkeletonNodeOffset.KNEE, SkeletonNodeOffset.ANKLE }),
|
||||
FOOT_LENGTH("Foot length", "footLength", 0.05f, new SkeletonNodeOffset[] { SkeletonNodeOffset.FOOT }),
|
||||
FOOT_OFFSET("Foot offset", "footOffset", 0.0f, new SkeletonNodeOffset[] { SkeletonNodeOffset.ANKLE }),
|
||||
HEAD("Head", "headShift", "Head shift", 0.1f, new SkeletonNodeOffset[] { SkeletonNodeOffset.HEAD }),
|
||||
NECK("Neck", "neckLength", "Neck length", 0.1f, new SkeletonNodeOffset[] { SkeletonNodeOffset.NECK }),
|
||||
TORSO("Torso", "torsoLength", "Torso length", 0.7f, new SkeletonNodeOffset[] { SkeletonNodeOffset.WAIST }),
|
||||
CHEST("Chest", "chestDistance", "Chest distance", 0.35f, new SkeletonNodeOffset[] { SkeletonNodeOffset.CHEST, SkeletonNodeOffset.WAIST }),
|
||||
WAIST("Waist", "waistDistance", "Waist distance", 0.1f, new SkeletonNodeOffset[] { SkeletonNodeOffset.WAIST, SkeletonNodeOffset.HIP }),
|
||||
HIP_OFFSET("Hip offset", "hipOffset", "Hip offset", 0.0f, new SkeletonNodeOffset[] { SkeletonNodeOffset.HIP_TRACKER }),
|
||||
HIPS_WIDTH("Hips width", "hipsWidth", "Hips width", 0.3f, new SkeletonNodeOffset[] { SkeletonNodeOffset.LEFT_HIP, SkeletonNodeOffset.RIGHT_HIP }),
|
||||
LEGS_LENGTH("Legs length", "legsLength", "Legs length", 0.84f, new SkeletonNodeOffset[] { SkeletonNodeOffset.KNEE }),
|
||||
KNEE_HEIGHT("Knee height", "kneeHeight", "Knee height", 0.42f, new SkeletonNodeOffset[] { SkeletonNodeOffset.KNEE, SkeletonNodeOffset.ANKLE }),
|
||||
FOOT_LENGTH("Foot length", "footLength", "Foot length", 0.05f, new SkeletonNodeOffset[] { SkeletonNodeOffset.FOOT }),
|
||||
FOOT_OFFSET("Foot offset", "footOffset", "Foot offset", 0.0f, new SkeletonNodeOffset[] { SkeletonNodeOffset.ANKLE }),
|
||||
;
|
||||
|
||||
private static final String CONFIG_PREFIX = "body.";
|
||||
|
||||
public final String stringVal;
|
||||
public final String configKey;
|
||||
public final String label;
|
||||
|
||||
public final float defaultValue;
|
||||
|
||||
@@ -30,9 +31,10 @@ public enum SkeletonConfigValue {
|
||||
public static final SkeletonConfigValue[] values = values();
|
||||
private static final Map<String, SkeletonConfigValue> byStringVal = new HashMap<>();
|
||||
|
||||
private SkeletonConfigValue(String stringVal, String configKey, float defaultValue, SkeletonNodeOffset[] affectedOffsets) {
|
||||
private SkeletonConfigValue(String stringVal, String configKey, String label, float defaultValue, SkeletonNodeOffset[] affectedOffsets) {
|
||||
this.stringVal = stringVal;
|
||||
this.configKey = CONFIG_PREFIX + configKey;
|
||||
this.label = label;
|
||||
|
||||
this.defaultValue = defaultValue;
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.function.Consumer;
|
||||
|
||||
import dev.slimevr.vr.processor.skeleton.HumanSkeleton;
|
||||
import dev.slimevr.vr.processor.skeleton.SimpleSkeleton;
|
||||
import dev.slimevr.vr.processor.skeleton.SkeletonConfigValue;
|
||||
import io.eiren.util.ann.ThreadSafe;
|
||||
import io.eiren.util.ann.VRServerThread;
|
||||
import io.eiren.util.collections.FastList;
|
||||
@@ -44,19 +45,25 @@ public class HumanPoseProcessor {
|
||||
}
|
||||
|
||||
@ThreadSafe
|
||||
public void setSkeletonConfig(String key, float newLength) {
|
||||
public void setSkeletonConfig(SkeletonConfigValue key, float newLength) {
|
||||
if(skeleton != null)
|
||||
skeleton.getSkeletonConfig().setConfig(key, newLength);
|
||||
}
|
||||
|
||||
@ThreadSafe
|
||||
public void resetSkeletonConfig(String key) {
|
||||
public void resetSkeletonConfig(SkeletonConfigValue key) {
|
||||
if(skeleton != null)
|
||||
skeleton.resetSkeletonConfig(key);
|
||||
}
|
||||
|
||||
@ThreadSafe
|
||||
public void resetAllSkeletonConfigs() {
|
||||
if(skeleton != null)
|
||||
skeleton.resetAllSkeletonConfigs();
|
||||
}
|
||||
|
||||
@ThreadSafe
|
||||
public float getSkeletonConfig(String key) {
|
||||
public float getSkeletonConfig(SkeletonConfigValue key) {
|
||||
if(skeleton != null) {
|
||||
Number f = skeleton.getSkeletonConfig().getConfig(key);
|
||||
if(f != null)
|
||||
|
||||
Reference in new issue
Block a user