mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-21 17:41:28 -08:00
Body proportions
This commit is contained in:
1 parent
5fbac9d861
commit
aaed8fbd49
7 files changed
+417
-41
No files matched your search
@@ -5,26 +5,27 @@ import java.util.Map;
|
||||
|
||||
public enum SkeletonConfigValue {
|
||||
|
||||
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.56f, new SkeletonNodeOffset[]{SkeletonNodeOffset.WAIST}),
|
||||
CHEST("Chest", "chestDistance", "Chest distance", 0.32f, new SkeletonNodeOffset[]{SkeletonNodeOffset.CHEST, SkeletonNodeOffset.WAIST}),
|
||||
WAIST("Waist", "waistDistance", "Waist distance", 0.04f, 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.26f, new SkeletonNodeOffset[]{SkeletonNodeOffset.LEFT_HIP, SkeletonNodeOffset.RIGHT_HIP}),
|
||||
LEGS_LENGTH("Legs length", "legsLength", "Legs length", 0.92f, new SkeletonNodeOffset[]{SkeletonNodeOffset.KNEE}),
|
||||
KNEE_HEIGHT("Knee height", "kneeHeight", "Knee height", 0.50f, 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.05f, new SkeletonNodeOffset[]{SkeletonNodeOffset.ANKLE}),
|
||||
SKELETON_OFFSET("Skeleton offset", "skeletonOffset", "Skeleton offset", 0.0f, new SkeletonNodeOffset[]{SkeletonNodeOffset.CHEST_TRACKER, SkeletonNodeOffset.HIP_TRACKER, SkeletonNodeOffset.KNEE_TRACKER, SkeletonNodeOffset.FOOT_TRACKER}),
|
||||
CONTROLLER_DISTANCE_Z("Controller distance z", "controllerDistanceZ", "Controller distance z", 0.15f, new SkeletonNodeOffset[]{SkeletonNodeOffset.HAND}),
|
||||
CONTROLLER_DISTANCE_Y("Controller distance y", "controllerDistanceY", "Controller distance y", 0.05f, new SkeletonNodeOffset[]{SkeletonNodeOffset.HAND}),
|
||||
ELBOW_DISTANCE("Elbow distance", "elbowDistance", "Elbow distance", 0.24f, new SkeletonNodeOffset[]{SkeletonNodeOffset.ELBOW}),
|
||||
UPPER_ARM_DISTANCE("Upper arm distance", "upperArmDistance", "Upper arm distance", 0.0f, new SkeletonNodeOffset[]{SkeletonNodeOffset.UPPER_ARM}),
|
||||
HEAD(1,"Head", "headShift", "Head shift", 0.1f, new SkeletonNodeOffset[]{SkeletonNodeOffset.HEAD}),
|
||||
NECK(2,"Neck", "neckLength", "Neck length", 0.1f, new SkeletonNodeOffset[]{SkeletonNodeOffset.NECK}),
|
||||
TORSO(3,"Torso", "torsoLength", "Torso length", 0.56f, new SkeletonNodeOffset[]{SkeletonNodeOffset.WAIST}),
|
||||
CHEST(4,"Chest", "chestDistance", "Chest distance", 0.32f, new SkeletonNodeOffset[]{SkeletonNodeOffset.CHEST, SkeletonNodeOffset.WAIST}),
|
||||
WAIST(5,"Waist", "waistDistance", "Waist distance", 0.04f, new SkeletonNodeOffset[]{SkeletonNodeOffset.WAIST, SkeletonNodeOffset.HIP}),
|
||||
HIP_OFFSET(6,"Hip offset", "hipOffset", "Hip offset", 0.0f, new SkeletonNodeOffset[]{SkeletonNodeOffset.HIP_TRACKER}),
|
||||
HIPS_WIDTH(7,"Hips width", "hipsWidth", "Hips width", 0.26f, new SkeletonNodeOffset[]{SkeletonNodeOffset.LEFT_HIP, SkeletonNodeOffset.RIGHT_HIP}),
|
||||
LEGS_LENGTH(8,"Legs length", "legsLength", "Legs length", 0.92f, new SkeletonNodeOffset[]{SkeletonNodeOffset.KNEE}),
|
||||
KNEE_HEIGHT(9,"Knee height", "kneeHeight", "Knee height", 0.50f, new SkeletonNodeOffset[]{SkeletonNodeOffset.KNEE, SkeletonNodeOffset.ANKLE}),
|
||||
FOOT_LENGTH(10,"Foot length", "footLength", "Foot length", 0.05f, new SkeletonNodeOffset[]{SkeletonNodeOffset.FOOT}),
|
||||
FOOT_OFFSET(11,"Foot offset", "footOffset", "Foot offset", -0.05f, new SkeletonNodeOffset[]{SkeletonNodeOffset.ANKLE}),
|
||||
SKELETON_OFFSET(12,"Skeleton offset", "skeletonOffset", "Skeleton offset", 0.0f, new SkeletonNodeOffset[]{SkeletonNodeOffset.CHEST_TRACKER, SkeletonNodeOffset.HIP_TRACKER, SkeletonNodeOffset.KNEE_TRACKER, SkeletonNodeOffset.FOOT_TRACKER}),
|
||||
CONTROLLER_DISTANCE_Z(13,"Controller distance z", "controllerDistanceZ", "Controller distance z", 0.15f, new SkeletonNodeOffset[]{SkeletonNodeOffset.HAND}),
|
||||
CONTROLLER_DISTANCE_Y(14,"Controller distance y", "controllerDistanceY", "Controller distance y", 0.05f, new SkeletonNodeOffset[]{SkeletonNodeOffset.HAND}),
|
||||
ELBOW_DISTANCE(15,"Elbow distance", "elbowDistance", "Elbow distance", 0.24f, new SkeletonNodeOffset[]{SkeletonNodeOffset.ELBOW}),
|
||||
UPPER_ARM_DISTANCE(16,"Upper arm distance", "upperArmDistance", "Upper arm distance", 0.0f, new SkeletonNodeOffset[]{SkeletonNodeOffset.UPPER_ARM}),
|
||||
;
|
||||
|
||||
private static final String CONFIG_PREFIX = "body.";
|
||||
|
||||
|
||||
public final int id;
|
||||
public final String stringVal;
|
||||
public final String configKey;
|
||||
public final String label;
|
||||
@@ -35,8 +36,10 @@ public enum SkeletonConfigValue {
|
||||
|
||||
public static final SkeletonConfigValue[] values = values();
|
||||
private static final Map<String, SkeletonConfigValue> byStringVal = new HashMap<>();
|
||||
private static final Map<Number, SkeletonConfigValue> byIdVal= new HashMap<>();
|
||||
|
||||
private SkeletonConfigValue(String stringVal, String configKey, String label, float defaultValue, SkeletonNodeOffset[] affectedOffsets) {
|
||||
private SkeletonConfigValue(int id, String stringVal, String configKey, String label, float defaultValue, SkeletonNodeOffset[] affectedOffsets) {
|
||||
this.id = id;
|
||||
this.stringVal = stringVal;
|
||||
this.configKey = CONFIG_PREFIX + configKey;
|
||||
this.label = label;
|
||||
@@ -49,9 +52,14 @@ public enum SkeletonConfigValue {
|
||||
public static SkeletonConfigValue getByStringValue(String stringVal) {
|
||||
return stringVal == null ? null : byStringVal.get(stringVal.toLowerCase());
|
||||
}
|
||||
|
||||
public static SkeletonConfigValue getById(int id) {
|
||||
return byIdVal.get(id);
|
||||
}
|
||||
|
||||
static {
|
||||
for(SkeletonConfigValue configVal : values()) {
|
||||
byIdVal.put(configVal.id, configVal);
|
||||
byStringVal.put(configVal.stringVal.toLowerCase(), configVal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,33 +6,36 @@ import java.util.Map;
|
||||
|
||||
public enum TrackerPosition {
|
||||
|
||||
NONE("", TrackerRole.NONE),
|
||||
HMD("HMD", TrackerRole.HMD),
|
||||
CHEST("body:chest", TrackerRole.CHEST),
|
||||
WAIST("body:waist", TrackerRole.WAIST),
|
||||
HIP("body:hip", null),
|
||||
LEFT_LEG("body:left_leg", TrackerRole.LEFT_KNEE),
|
||||
RIGHT_LEG("body:right_leg", TrackerRole.RIGHT_KNEE),
|
||||
LEFT_ANKLE("body:left_ankle", null),
|
||||
RIGHT_ANKLE("body:right_ankle", null),
|
||||
LEFT_FOOT("body:left_foot", TrackerRole.LEFT_FOOT),
|
||||
RIGHT_FOOT("body:right_foot", TrackerRole.RIGHT_FOOT),
|
||||
LEFT_CONTROLLER("body:left_controller", TrackerRole.LEFT_CONTROLLER),
|
||||
RIGHT_CONTROLLER("body:right_controller", TrackerRole.RIGHT_CONTROLLER),
|
||||
LEFT_FOREARM("body:left_forearm", TrackerRole.LEFT_ELBOW),
|
||||
RIGHT_FOREARM("body:right_forearm", TrackerRole.RIGHT_ELBOW),
|
||||
LEFT_UPPER_ARM("body:left_upperarm", null),
|
||||
RIGHT_UPPER_ARM("body:right_upperarm", null),
|
||||
NONE(0,"", TrackerRole.NONE),
|
||||
HMD(1,"HMD", TrackerRole.HMD),
|
||||
CHEST(2,"body:chest", TrackerRole.CHEST),
|
||||
WAIST(3,"body:waist", TrackerRole.WAIST),
|
||||
HIP(4,"body:hip", null),
|
||||
LEFT_LEG(5,"body:left_leg", TrackerRole.LEFT_KNEE),
|
||||
RIGHT_LEG(6,"body:right_leg", TrackerRole.RIGHT_KNEE),
|
||||
LEFT_ANKLE(7,"body:left_ankle", null),
|
||||
RIGHT_ANKLE(8,"body:right_ankle", null),
|
||||
LEFT_FOOT(9,"body:left_foot", TrackerRole.LEFT_FOOT),
|
||||
RIGHT_FOOT(10,"body:right_foot", TrackerRole.RIGHT_FOOT),
|
||||
LEFT_CONTROLLER(11,"body:left_controller", TrackerRole.LEFT_CONTROLLER),
|
||||
RIGHT_CONTROLLER(12,"body:right_controller", TrackerRole.RIGHT_CONTROLLER),
|
||||
LEFT_FOREARM(13,"body:left_forearm", TrackerRole.LEFT_ELBOW),
|
||||
RIGHT_FOREARM(14,"body:right_forearm", TrackerRole.RIGHT_ELBOW),
|
||||
LEFT_UPPER_ARM(15,"body:left_upperarm", null),
|
||||
RIGHT_UPPER_ARM(16,"body:right_upperarm", null),
|
||||
;
|
||||
|
||||
|
||||
public final int id;
|
||||
public final String designation;
|
||||
public final TrackerRole trackerRole;
|
||||
|
||||
public static final TrackerPosition[] values = values();
|
||||
private static final Map<Integer, TrackerPosition> byId = new HashMap<>();
|
||||
private static final Map<String, TrackerPosition> byDesignation = new HashMap<>();
|
||||
private static final EnumMap<TrackerRole, TrackerPosition> byRole = new EnumMap<>(TrackerRole.class);
|
||||
|
||||
private TrackerPosition(String designation, TrackerRole trackerRole) {
|
||||
private TrackerPosition(int id, String designation, TrackerRole trackerRole) {
|
||||
this.id = id;
|
||||
this.designation = designation;
|
||||
this.trackerRole = trackerRole;
|
||||
}
|
||||
@@ -44,10 +47,15 @@ public enum TrackerPosition {
|
||||
public static TrackerPosition getByRole(TrackerRole role) {
|
||||
return byRole.get(role);
|
||||
}
|
||||
|
||||
public static TrackerPosition getById(int id) {
|
||||
return byId.get(id);
|
||||
}
|
||||
|
||||
static {
|
||||
for(TrackerPosition tbp : values()) {
|
||||
byDesignation.put(tbp.designation.toLowerCase(), tbp);
|
||||
byId.put(tbp.id, tbp);
|
||||
if(tbp.trackerRole != null) {
|
||||
TrackerPosition old = byRole.get(tbp.trackerRole);
|
||||
if(old != null)
|
||||
|
||||
@@ -6,7 +6,9 @@ import com.jme3.math.Vector3f;
|
||||
import dev.slimevr.VRServer;
|
||||
import dev.slimevr.bridge.ProtobufBridge;
|
||||
import dev.slimevr.platform.windows.WindowsNamedPipeBridge;
|
||||
import dev.slimevr.vr.processor.skeleton.SkeletonConfigValue;
|
||||
import dev.slimevr.vr.trackers.*;
|
||||
import dev.slimevr.vr.trackers.TrackerPosition;
|
||||
import dev.slimevr.vr.trackers.TrackerRole;
|
||||
import io.eiren.util.ann.ThreadSafe;
|
||||
import io.eiren.util.logging.LogManager;
|
||||
@@ -92,6 +94,16 @@ public class WebsocketAPI extends WebSocketServer {
|
||||
if (req != null) this.onChangeSettingsRequest(conn, req);
|
||||
break;
|
||||
}
|
||||
case InboundUnion.SkeletonConfigRequest: {
|
||||
SkeletonConfigRequest req = (SkeletonConfigRequest) inboundPacket.packet(new SkeletonConfigRequest());
|
||||
if (req != null) this.onSkeletonConfigRequest(conn, req);
|
||||
break;
|
||||
}
|
||||
case InboundUnion.ChangeSkeletonConfigRequest: {
|
||||
ChangeSkeletonConfigRequest req = (ChangeSkeletonConfigRequest) inboundPacket.packet(new ChangeSkeletonConfigRequest());
|
||||
if (req != null) this.onChangeSkeletonConfigRequest(conn, req);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LogManager.log.warning("[WebSocketAPI] Received unknown packet type: " + inboundPacket.packetType());
|
||||
}
|
||||
@@ -109,8 +121,37 @@ public class WebsocketAPI extends WebSocketServer {
|
||||
}
|
||||
}
|
||||
|
||||
public void onSkeletonConfigRequest(WebSocket conn, SkeletonConfigRequest req) {
|
||||
FlatBufferBuilder fbb = new FlatBufferBuilder(300);
|
||||
|
||||
int[] partsOffsets = new int[SkeletonConfigValue.values().length];
|
||||
|
||||
|
||||
for (int index = 0; index < SkeletonConfigValue.values().length; index++) {
|
||||
SkeletonConfigValue val = SkeletonConfigValue.values[index];
|
||||
int part = SkeletonPart.createSkeletonPart(fbb, val.id, this.server.humanPoseProcessor.getSkeletonConfig(val));
|
||||
partsOffsets[index] = part;
|
||||
}
|
||||
|
||||
|
||||
int parts = SkeletonConfigResponse.createSkeletonPartsVector(fbb, partsOffsets);
|
||||
int config = SkeletonConfigResponse.createSkeletonConfigResponse(fbb, parts);
|
||||
int outbound = this.createOutboundPacket(fbb, OutboundUnion.SkeletonConfigResponse, config);
|
||||
fbb.finish(outbound);
|
||||
conn.send(fbb.dataBuffer());
|
||||
}
|
||||
|
||||
public void onChangeSkeletonConfigRequest(WebSocket conn, ChangeSkeletonConfigRequest req) {
|
||||
SkeletonConfigValue joint = SkeletonConfigValue.getById(req.id());
|
||||
|
||||
// float current = server.humanPoseProcessor.getSkeletonConfig(SkeletonConfigValue.getById(req.id()));
|
||||
server.humanPoseProcessor.setSkeletonConfig(joint, req.value());
|
||||
server.humanPoseProcessor.getSkeletonConfig().saveToConfig(server.config);
|
||||
server.saveConfig();
|
||||
}
|
||||
|
||||
public void onSettingsRequest(WebSocket conn, SettingsRequest req) {
|
||||
FlatBufferBuilder fbb = new FlatBufferBuilder(40);
|
||||
FlatBufferBuilder fbb = new FlatBufferBuilder(32);
|
||||
|
||||
WindowsNamedPipeBridge bridge = this.server.getVRBridge(WindowsNamedPipeBridge.class);
|
||||
|
||||
@@ -170,7 +211,7 @@ public class WebsocketAPI extends WebSocketServer {
|
||||
if (tracker == null)
|
||||
return ;
|
||||
|
||||
tracker.setBodyPosition(TrackerPosition.getByRole(TrackerRole.getById(req.role())));
|
||||
tracker.setBodyPosition(TrackerPosition.getById(req.mountingPosition()));
|
||||
if (tracker instanceof IMUTracker) {
|
||||
IMUTracker imu = (IMUTracker) tracker;
|
||||
TrackerMountingRotation rot = TrackerMountingRotation.fromAngle(req.mountingRotation());
|
||||
@@ -215,8 +256,8 @@ public class WebsocketAPI extends WebSocketServer {
|
||||
DeviceStatus.addComputed(fbb, tracker.isComputed());
|
||||
DeviceStatus.addEditable(fbb, tracker.userEditable());
|
||||
|
||||
if (tracker.getBodyPosition() != null && tracker.getBodyPosition().trackerRole != null) {
|
||||
DeviceStatus.addRole(fbb, tracker.getBodyPosition().trackerRole.id);
|
||||
if (tracker.getBodyPosition() != null) {
|
||||
DeviceStatus.addMountingPosition(fbb, tracker.getBodyPosition().id);
|
||||
}
|
||||
|
||||
if (tracker instanceof IMUTracker) {
|
||||
|
||||
Reference in new issue
Block a user