mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-20 17:11:20 -08:00
Add new SkeletonConfig class for configuring bone lengths and toggles
This commit is contained in:
7 files changed
+231
-5
No files matched your search
@@ -37,7 +37,7 @@ public class AutoBoneWindow extends JFrame {
|
||||
private EJBox pane;
|
||||
|
||||
private final transient VRServer server;
|
||||
private final transient SkeletonConfig skeletonConfig;
|
||||
private final transient SkeletonConfigGUI skeletonConfig;
|
||||
private final transient PoseRecorder poseRecorder;
|
||||
private final transient AutoBone autoBone;
|
||||
|
||||
@@ -52,7 +52,7 @@ public class AutoBoneWindow extends JFrame {
|
||||
private JLabel processLabel;
|
||||
private JLabel lengthsLabel;
|
||||
|
||||
public AutoBoneWindow(VRServer server, SkeletonConfig skeletonConfig) {
|
||||
public AutoBoneWindow(VRServer server, SkeletonConfigGUI skeletonConfig) {
|
||||
super("Skeleton Auto-Configuration");
|
||||
|
||||
this.server = server;
|
||||
|
||||
+2
-2
@@ -15,14 +15,14 @@ import io.eiren.util.ann.ThreadSafe;
|
||||
import io.eiren.vr.VRServer;
|
||||
import io.eiren.vr.processor.HumanSkeleton;
|
||||
|
||||
public class SkeletonConfig extends EJBagNoStretch {
|
||||
public class SkeletonConfigGUI extends EJBagNoStretch {
|
||||
|
||||
private final VRServer server;
|
||||
private final VRServerGUI gui;
|
||||
private final AutoBoneWindow autoBone;
|
||||
private Map<String, SkeletonLabel> labels = new HashMap<>();
|
||||
|
||||
public SkeletonConfig(VRServer server, VRServerGUI gui) {
|
||||
public SkeletonConfigGUI(VRServer server, VRServerGUI gui) {
|
||||
super(false, true);
|
||||
this.server = server;
|
||||
this.gui = gui;
|
||||
@@ -202,7 +202,7 @@ public class VRServerGUI extends JFrame {
|
||||
add(l = new JLabel("Body proportions"));
|
||||
l.setFont(l.getFont().deriveFont(Font.BOLD));
|
||||
l.setAlignmentX(0.5f);
|
||||
add(new SkeletonConfig(server, VRServerGUI.this));
|
||||
add(new SkeletonConfigGUI(server, VRServerGUI.this));
|
||||
add(Box.createVerticalStrut(10));
|
||||
if(server.hasBridge(NamedPipeBridge.class)) {
|
||||
NamedPipeBridge br = server.getVRBridge(NamedPipeBridge.class);
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
package dev.slimevr.vr.processor;
|
||||
|
||||
import java.util.EnumMap;
|
||||
|
||||
import com.jme3.math.Vector3f;
|
||||
|
||||
public class SkeletonConfig {
|
||||
|
||||
protected final EnumMap<SkeletonConfigValue, Float> configs = new EnumMap<SkeletonConfigValue, Float>(SkeletonConfigValue.class);
|
||||
protected final EnumMap<SkeletonConfigToggle, Boolean> toggles = new EnumMap<SkeletonConfigToggle, Boolean>(SkeletonConfigToggle.class);
|
||||
protected final EnumMap<SkeletonNodeOffset, Vector3f> nodeOffsets = new EnumMap<SkeletonNodeOffset, Vector3f>(SkeletonNodeOffset.class);
|
||||
|
||||
public SkeletonConfig() {
|
||||
// Setup node offsets
|
||||
computeAllNodeOffsets();
|
||||
}
|
||||
|
||||
public Float setConfig(SkeletonConfigValue config, float newValue) {
|
||||
Float origVal = configs.put(config, newValue);
|
||||
|
||||
// Re-compute the affected offsets
|
||||
if (config.affectedOffsets != null) {
|
||||
for (SkeletonNodeOffset offset : config.affectedOffsets) {
|
||||
computeNodeOffset(offset);
|
||||
}
|
||||
}
|
||||
|
||||
return origVal;
|
||||
}
|
||||
|
||||
public Float setConfig(String config, float newValue) {
|
||||
return setConfig(SkeletonConfigValue.getByStringValue(config), newValue);
|
||||
}
|
||||
|
||||
public float getConfig(SkeletonConfigValue config) {
|
||||
return configs.getOrDefault(config, config.defaultValue);
|
||||
}
|
||||
|
||||
public float getConfig(String config) {
|
||||
return getConfig(SkeletonConfigValue.getByStringValue(config));
|
||||
}
|
||||
|
||||
public Boolean setConfigToggle(SkeletonConfigToggle config, boolean newValue) {
|
||||
return toggles.put(config, newValue);
|
||||
}
|
||||
|
||||
public Boolean setConfigToggle(String config, boolean newValue) {
|
||||
return setConfigToggle(SkeletonConfigToggle.getByStringValue(config), newValue);
|
||||
}
|
||||
|
||||
public boolean getConfigToggle(SkeletonConfigToggle config) {
|
||||
return toggles.getOrDefault(config, config.defaultValue);
|
||||
}
|
||||
|
||||
public boolean getConfigToggle(String config) {
|
||||
return getConfigToggle(SkeletonConfigToggle.getByStringValue(config));
|
||||
}
|
||||
|
||||
protected void setNodeOffset(SkeletonNodeOffset nodeOffset, float x, float y, float z) {
|
||||
Vector3f offset = nodeOffsets.get(nodeOffset);
|
||||
|
||||
if (offset == null) {
|
||||
nodeOffsets.put(nodeOffset, new Vector3f(x, y, z));
|
||||
} else {
|
||||
offset.set(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3f getNodeOffset(SkeletonNodeOffset nodeOffset) {
|
||||
return nodeOffsets.getOrDefault(nodeOffset, Vector3f.ZERO);
|
||||
}
|
||||
|
||||
protected void computeNodeOffset(SkeletonNodeOffset nodeOffset) {
|
||||
switch (nodeOffset) {
|
||||
case HEAD:
|
||||
setNodeOffset(nodeOffset, 0, 0, getConfig(SkeletonConfigValue.HEAD));
|
||||
break;
|
||||
case NECK:
|
||||
setNodeOffset(nodeOffset, 0, -getConfig(SkeletonConfigValue.NECK), 0);
|
||||
break;
|
||||
case CHEST:
|
||||
setNodeOffset(nodeOffset, 0, -getConfig(SkeletonConfigValue.CHEST), 0);
|
||||
break;
|
||||
case WAIST:
|
||||
setNodeOffset(nodeOffset, 0, (getConfig(SkeletonConfigValue.CHEST) - getConfig(SkeletonConfigValue.TORSO) + getConfig(SkeletonConfigValue.WAIST)), 0);
|
||||
break;
|
||||
case HIP:
|
||||
setNodeOffset(nodeOffset, 0, -getConfig(SkeletonConfigValue.WAIST), 0);
|
||||
break;
|
||||
case HIP_TRACKER:
|
||||
setNodeOffset(nodeOffset, 0, getConfig(SkeletonConfigValue.HIP_OFFSET), 0);
|
||||
break;
|
||||
|
||||
case LEFT_HIP:
|
||||
setNodeOffset(nodeOffset, -getConfig(SkeletonConfigValue.HIPS_WIDTH) / 2f, 0, 0);
|
||||
break;
|
||||
case RIGHT_HIP:
|
||||
setNodeOffset(nodeOffset, getConfig(SkeletonConfigValue.HIPS_WIDTH) / 2f, 0, 0);
|
||||
break;
|
||||
|
||||
case KNEE:
|
||||
setNodeOffset(nodeOffset, 0, -(getConfig(SkeletonConfigValue.LEGS_LENGTH) - getConfig(SkeletonConfigValue.KNEE_HEIGHT)), 0);
|
||||
break;
|
||||
case ANKLE:
|
||||
setNodeOffset(nodeOffset, 0, -getConfig(SkeletonConfigValue.KNEE_HEIGHT), -getConfig(SkeletonConfigValue.FOOT_OFFSET));
|
||||
break;
|
||||
case FOOT:
|
||||
setNodeOffset(nodeOffset, 0, 0, -getConfig(SkeletonConfigValue.FOOT_LENGTH));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected void computeAllNodeOffsets() {
|
||||
for (SkeletonNodeOffset offset : SkeletonNodeOffset.values) {
|
||||
computeNodeOffset(offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package dev.slimevr.vr.processor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public enum SkeletonConfigToggle {
|
||||
|
||||
EXTENDED_PELVIS_MODEL("Extended pelvis model", "extendedPelvis", true),
|
||||
EXTENDED_KNEE_MODEL("Extended knee model", "extendedKnee", false),
|
||||
;
|
||||
|
||||
private static final String CONFIG_PREFIX = "body.model.";
|
||||
|
||||
public final String stringVal;
|
||||
public final String configKey;
|
||||
|
||||
public final boolean defaultValue;
|
||||
|
||||
public static final SkeletonConfigToggle[] values = values();
|
||||
private static final Map<String, SkeletonConfigToggle> byStringVal = new HashMap<>();
|
||||
|
||||
private SkeletonConfigToggle(String stringVal, String configKey, boolean defaultValue) {
|
||||
this.stringVal = stringVal;
|
||||
this.configKey = CONFIG_PREFIX + configKey;
|
||||
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public static SkeletonConfigToggle getByStringValue(String stringVal) {
|
||||
return stringVal == null ? null : byStringVal.get(stringVal.toLowerCase());
|
||||
}
|
||||
|
||||
static {
|
||||
for (SkeletonConfigToggle configVal : values()) {
|
||||
byStringVal.put(configVal.stringVal.toLowerCase(), configVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package dev.slimevr.vr.processor;
|
||||
|
||||
import java.util.HashMap;
|
||||
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 }),
|
||||
;
|
||||
|
||||
private static final String CONFIG_PREFIX = "body.";
|
||||
|
||||
public final String stringVal;
|
||||
public final String configKey;
|
||||
|
||||
public final float defaultValue;
|
||||
|
||||
public final SkeletonNodeOffset[] affectedOffsets;
|
||||
|
||||
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) {
|
||||
this.stringVal = stringVal;
|
||||
this.configKey = CONFIG_PREFIX + configKey;
|
||||
|
||||
this.defaultValue = defaultValue;
|
||||
|
||||
this.affectedOffsets = affectedOffsets == null ? new SkeletonNodeOffset[0] : affectedOffsets;
|
||||
}
|
||||
|
||||
public static SkeletonConfigValue getByStringValue(String stringVal) {
|
||||
return stringVal == null ? null : byStringVal.get(stringVal.toLowerCase());
|
||||
}
|
||||
|
||||
static {
|
||||
for (SkeletonConfigValue configVal : values()) {
|
||||
byStringVal.put(configVal.stringVal.toLowerCase(), configVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package dev.slimevr.vr.processor;
|
||||
|
||||
public enum SkeletonNodeOffset {
|
||||
|
||||
HEAD,
|
||||
NECK,
|
||||
CHEST,
|
||||
WAIST,
|
||||
HIP,
|
||||
HIP_TRACKER,
|
||||
LEFT_HIP,
|
||||
RIGHT_HIP,
|
||||
KNEE,
|
||||
ANKLE,
|
||||
FOOT,
|
||||
;
|
||||
|
||||
public static final SkeletonNodeOffset[] values = values();
|
||||
}
|
||||
Reference in new issue
Block a user