mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-26 03:46:28 -08:00
Make SimpleSkeleton compatible with HumanSkeleton
This commit is contained in:
6 files changed
+266
-28
No files matched your search
@@ -65,7 +65,7 @@ public class AutoBone {
|
||||
public float positionErrorFactor = 0.0f;
|
||||
public float positionOffsetErrorFactor = 0.0f;
|
||||
|
||||
// TODO Needs much more work, probably going to rethink how the errors work to avoid this barely functional workaround -Butterscotch
|
||||
// TODO Needs much more work, probably going to rethink how the errors work to avoid this barely functional workaround @ButterscotchVanilla
|
||||
// For scaling distances, since smaller sizes will cause smaller distances
|
||||
//private float totalLengthBase = 2f;
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package dev.slimevr.vr.processor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -8,10 +7,12 @@ import com.jme3.math.FastMath;
|
||||
import com.jme3.math.Quaternion;
|
||||
import com.jme3.math.Vector3f;
|
||||
|
||||
import io.eiren.util.ann.VRServerThread;
|
||||
import io.eiren.util.collections.FastList;
|
||||
import io.eiren.vr.VRServer;
|
||||
import io.eiren.vr.processor.ComputedHumanPoseTracker;
|
||||
import io.eiren.vr.processor.ComputedHumanPoseTrackerPosition;
|
||||
import io.eiren.vr.processor.HumanSkeleton;
|
||||
import io.eiren.vr.processor.TransformNode;
|
||||
import io.eiren.vr.trackers.Tracker;
|
||||
import io.eiren.vr.trackers.TrackerPosition;
|
||||
@@ -19,8 +20,10 @@ import io.eiren.vr.trackers.TrackerRole;
|
||||
import io.eiren.vr.trackers.TrackerStatus;
|
||||
import io.eiren.vr.trackers.TrackerUtils;
|
||||
|
||||
public class SimpleSkeleton implements SkeletonConfigCallback {
|
||||
public class SimpleSkeleton extends HumanSkeleton implements SkeletonConfigCallback {
|
||||
|
||||
public static final float DEFAULT_FLOOR_OFFSET = 0.05f;
|
||||
|
||||
//#region Upper body nodes (torso)
|
||||
protected final TransformNode hmdNode = new TransformNode("HMD", false);
|
||||
protected final TransformNode headNode = new TransformNode("Head", false);
|
||||
@@ -287,6 +290,8 @@ public class SimpleSkeleton implements SkeletonConfigCallback {
|
||||
}
|
||||
|
||||
// Updates the pose from tracker positions
|
||||
@VRServerThread
|
||||
@Override
|
||||
public void updatePose() {
|
||||
updateLocalTransforms();
|
||||
hmdNode.update();
|
||||
@@ -585,4 +590,181 @@ public class SimpleSkeleton implements SkeletonConfigCallback {
|
||||
}
|
||||
}
|
||||
//#endregion
|
||||
|
||||
@Override
|
||||
public TransformNode getRootNode() {
|
||||
return hmdNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SkeletonConfig getSkeletonConfig() {
|
||||
return skeletonConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetSkeletonConfig(SkeletonConfigValue config) {
|
||||
Vector3f vec;
|
||||
float height;
|
||||
switch(config) {
|
||||
case HEAD:
|
||||
skeletonConfig.setConfig(SkeletonConfigValue.HEAD, null);
|
||||
break;
|
||||
case NECK:
|
||||
skeletonConfig.setConfig(SkeletonConfigValue.NECK, null);
|
||||
break;
|
||||
case TORSO: // Distance from shoulders to hip (full torso length)
|
||||
vec = new Vector3f();
|
||||
hmdTracker.getPosition(vec);
|
||||
height = vec.y;
|
||||
if(height > 0.5f) { // Reset only if floor level is right, TODO: read floor level from SteamVR if it's not 0
|
||||
skeletonConfig.setConfig(SkeletonConfigValue.TORSO, ((height) / 2.0f) - skeletonConfig.getConfig(SkeletonConfigValue.NECK));
|
||||
}
|
||||
else// if floor level is incorrect
|
||||
{
|
||||
skeletonConfig.setConfig(SkeletonConfigValue.TORSO, null);
|
||||
}
|
||||
break;
|
||||
case CHEST: //Chest is roughly half of the upper body (shoulders to chest)
|
||||
skeletonConfig.setConfig(SkeletonConfigValue.CHEST, skeletonConfig.getConfig(SkeletonConfigValue.TORSO) / 2.0f);
|
||||
break;
|
||||
case WAIST: // waist length is from hips to waist
|
||||
skeletonConfig.setConfig(SkeletonConfigValue.WAIST, null);
|
||||
break;
|
||||
case HIP_OFFSET:
|
||||
skeletonConfig.setConfig(SkeletonConfigValue.HIP_OFFSET, null);
|
||||
break;
|
||||
case HIPS_WIDTH:
|
||||
skeletonConfig.setConfig(SkeletonConfigValue.HIPS_WIDTH, null);
|
||||
break;
|
||||
case FOOT_LENGTH:
|
||||
skeletonConfig.setConfig(SkeletonConfigValue.FOOT_LENGTH, null);
|
||||
break;
|
||||
case FOOT_OFFSET:
|
||||
skeletonConfig.setConfig(SkeletonConfigValue.FOOT_OFFSET, null);
|
||||
break;
|
||||
case LEGS_LENGTH: // Set legs length to be 5cm above floor level
|
||||
vec = new Vector3f();
|
||||
hmdTracker.getPosition(vec);
|
||||
height = vec.y;
|
||||
if(height > 0.5f) { // Reset only if floor level is right, todo: read floor level from SteamVR if it's not 0
|
||||
skeletonConfig.setConfig(SkeletonConfigValue.LEGS_LENGTH, height - skeletonConfig.getConfig(SkeletonConfigValue.NECK) - skeletonConfig.getConfig(SkeletonConfigValue.TORSO) - DEFAULT_FLOOR_OFFSET);
|
||||
}
|
||||
else //if floor level is incorrect
|
||||
{
|
||||
skeletonConfig.setConfig(SkeletonConfigValue.LEGS_LENGTH, null);
|
||||
}
|
||||
resetSkeletonConfig(SkeletonConfigValue.KNEE_HEIGHT);
|
||||
break;
|
||||
case KNEE_HEIGHT: // Knees are at 50% of the legs by default
|
||||
skeletonConfig.setConfig(SkeletonConfigValue.KNEE_HEIGHT, skeletonConfig.getConfig(SkeletonConfigValue.LEGS_LENGTH) / 2.0f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetTrackersFull() {
|
||||
//#region Pass all trackers through trackerPreUpdate
|
||||
Tracker hmdTracker = trackerPreUpdate(this.hmdTracker);
|
||||
|
||||
Tracker chestTracker = trackerPreUpdate(this.chestTracker);
|
||||
Tracker waistTracker = trackerPreUpdate(this.waistTracker);
|
||||
Tracker hipTracker = trackerPreUpdate(this.hipTracker);
|
||||
|
||||
Tracker leftLegTracker = trackerPreUpdate(this.leftLegTracker);
|
||||
Tracker leftAnkleTracker = trackerPreUpdate(this.leftAnkleTracker);
|
||||
Tracker leftFootTracker = trackerPreUpdate(this.leftFootTracker);
|
||||
|
||||
Tracker rightLegTracker = trackerPreUpdate(this.rightLegTracker);
|
||||
Tracker rightAnkleTracker = trackerPreUpdate(this.rightAnkleTracker);
|
||||
Tracker rightFootTracker = trackerPreUpdate(this.rightFootTracker);
|
||||
//#endregion
|
||||
|
||||
// Each tracker uses the tracker before it to adjust itself,
|
||||
// so trackers that don't need adjustments could be used too
|
||||
Quaternion referenceRotation = new Quaternion();
|
||||
hmdTracker.getRotation(referenceRotation);
|
||||
|
||||
chestTracker.resetFull(referenceRotation);
|
||||
chestTracker.getRotation(referenceRotation);
|
||||
|
||||
waistTracker.resetFull(referenceRotation);
|
||||
waistTracker.getRotation(referenceRotation);
|
||||
|
||||
hipTracker.resetFull(referenceRotation);
|
||||
hipTracker.getRotation(referenceRotation);
|
||||
|
||||
leftLegTracker.resetFull(referenceRotation);
|
||||
rightLegTracker.resetFull(referenceRotation);
|
||||
leftLegTracker.getRotation(referenceRotation);
|
||||
|
||||
leftAnkleTracker.resetFull(referenceRotation);
|
||||
leftAnkleTracker.getRotation(referenceRotation);
|
||||
|
||||
if(leftFootTracker != null) {
|
||||
leftFootTracker.resetFull(referenceRotation);
|
||||
}
|
||||
|
||||
rightLegTracker.getRotation(referenceRotation);
|
||||
|
||||
rightAnkleTracker.resetFull(referenceRotation);
|
||||
rightAnkleTracker.getRotation(referenceRotation);
|
||||
|
||||
if(rightFootTracker != null) {
|
||||
rightFootTracker.resetFull(referenceRotation);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@VRServerThread
|
||||
public void resetTrackersYaw() {
|
||||
//#region Pass all trackers through trackerPreUpdate
|
||||
Tracker hmdTracker = trackerPreUpdate(this.hmdTracker);
|
||||
|
||||
Tracker chestTracker = trackerPreUpdate(this.chestTracker);
|
||||
Tracker waistTracker = trackerPreUpdate(this.waistTracker);
|
||||
Tracker hipTracker = trackerPreUpdate(this.hipTracker);
|
||||
|
||||
Tracker leftLegTracker = trackerPreUpdate(this.leftLegTracker);
|
||||
Tracker leftAnkleTracker = trackerPreUpdate(this.leftAnkleTracker);
|
||||
Tracker leftFootTracker = trackerPreUpdate(this.leftFootTracker);
|
||||
|
||||
Tracker rightLegTracker = trackerPreUpdate(this.rightLegTracker);
|
||||
Tracker rightAnkleTracker = trackerPreUpdate(this.rightAnkleTracker);
|
||||
Tracker rightFootTracker = trackerPreUpdate(this.rightFootTracker);
|
||||
//#endregion
|
||||
|
||||
// Each tracker uses the tracker before it to adjust itself,
|
||||
// so trackers that don't need adjustments could be used too
|
||||
Quaternion referenceRotation = new Quaternion();
|
||||
hmdTracker.getRotation(referenceRotation);
|
||||
|
||||
chestTracker.resetYaw(referenceRotation);
|
||||
chestTracker.getRotation(referenceRotation);
|
||||
|
||||
waistTracker.resetYaw(referenceRotation);
|
||||
waistTracker.getRotation(referenceRotation);
|
||||
|
||||
hipTracker.resetYaw(referenceRotation);
|
||||
hipTracker.getRotation(referenceRotation);
|
||||
|
||||
leftLegTracker.resetYaw(referenceRotation);
|
||||
rightLegTracker.resetYaw(referenceRotation);
|
||||
leftLegTracker.getRotation(referenceRotation);
|
||||
|
||||
leftAnkleTracker.resetYaw(referenceRotation);
|
||||
leftAnkleTracker.getRotation(referenceRotation);
|
||||
|
||||
if(leftFootTracker != null) {
|
||||
leftFootTracker.resetYaw(referenceRotation);
|
||||
}
|
||||
|
||||
rightLegTracker.getRotation(referenceRotation);
|
||||
|
||||
rightAnkleTracker.resetYaw(referenceRotation);
|
||||
rightAnkleTracker.getRotation(referenceRotation);
|
||||
|
||||
if(rightFootTracker != null) {
|
||||
rightFootTracker.resetYaw(referenceRotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,8 @@ public class SkeletonConfig {
|
||||
this.autoUpdateOffsets = autoUpdateOffsets;
|
||||
this.callback = null;
|
||||
|
||||
callCallbackOnAll(true);
|
||||
|
||||
if (autoUpdateOffsets) {
|
||||
computeAllNodeOffsets();
|
||||
}
|
||||
@@ -29,7 +31,9 @@ public class SkeletonConfig {
|
||||
public SkeletonConfig(boolean autoUpdateOffsets, SkeletonConfigCallback callback) {
|
||||
this.autoUpdateOffsets = autoUpdateOffsets;
|
||||
this.callback = callback;
|
||||
|
||||
|
||||
callCallbackOnAll(true);
|
||||
|
||||
if (autoUpdateOffsets) {
|
||||
computeAllNodeOffsets();
|
||||
}
|
||||
@@ -39,6 +43,8 @@ public class SkeletonConfig {
|
||||
this.autoUpdateOffsets = autoUpdateOffsets;
|
||||
this.callback = callback;
|
||||
setConfigs(configs, toggles);
|
||||
|
||||
callCallbackOnAll(true);
|
||||
}
|
||||
|
||||
public SkeletonConfig(Map<SkeletonConfigValue, Float> configs, Map<SkeletonConfigToggle, Boolean> toggles, boolean autoUpdateOffsets) {
|
||||
@@ -49,13 +55,43 @@ public class SkeletonConfig {
|
||||
this.autoUpdateOffsets = autoUpdateOffsets;
|
||||
this.callback = callback;
|
||||
setConfigs(skeletonConfig);
|
||||
|
||||
callCallbackOnAll(true);
|
||||
}
|
||||
|
||||
public SkeletonConfig(SkeletonConfig skeletonConfig, boolean autoUpdateOffsets) {
|
||||
this(skeletonConfig, autoUpdateOffsets, null);
|
||||
}
|
||||
|
||||
public Float setConfig(SkeletonConfigValue config, float newValue) {
|
||||
private void callCallbackOnAll(boolean defaultOnly) {
|
||||
for (SkeletonConfigValue config : SkeletonConfigValue.values) {
|
||||
if (callback != null) {
|
||||
try {
|
||||
Float val = configs.get(config);
|
||||
if (!defaultOnly || val == null) {
|
||||
callback.updateConfigState(config, val == null ? config.defaultValue : val);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogManager.log.severe("[SkeletonConfig] Exception while calling callback", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (SkeletonConfigToggle config : SkeletonConfigToggle.values) {
|
||||
if (callback != null) {
|
||||
try {
|
||||
Boolean val = toggles.get(config);
|
||||
if (!defaultOnly || val == null) {
|
||||
callback.updateToggleState(config, val == null ? config.defaultValue : val);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogManager.log.severe("[SkeletonConfig] Exception while calling callback", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Float setConfig(SkeletonConfigValue config, Float newValue) {
|
||||
Float origVal = configs.put(config, newValue);
|
||||
|
||||
// Re-compute the affected offsets
|
||||
@@ -67,7 +103,7 @@ public class SkeletonConfig {
|
||||
|
||||
if (callback != null) {
|
||||
try {
|
||||
callback.updateConfigState(config, newValue);
|
||||
callback.updateConfigState(config, newValue != null ? newValue : config.defaultValue);
|
||||
} catch (Exception e) {
|
||||
LogManager.log.severe("[SkeletonConfig] Exception while calling callback", e);
|
||||
}
|
||||
@@ -76,7 +112,7 @@ public class SkeletonConfig {
|
||||
return origVal;
|
||||
}
|
||||
|
||||
public Float setConfig(String config, float newValue) {
|
||||
public Float setConfig(String config, Float newValue) {
|
||||
return setConfig(SkeletonConfigValue.getByStringValue(config), newValue);
|
||||
}
|
||||
|
||||
@@ -88,12 +124,12 @@ public class SkeletonConfig {
|
||||
return getConfig(SkeletonConfigValue.getByStringValue(config));
|
||||
}
|
||||
|
||||
public Boolean setToggle(SkeletonConfigToggle config, boolean newValue) {
|
||||
public Boolean setToggle(SkeletonConfigToggle config, Boolean newValue) {
|
||||
Boolean origVal = toggles.put(config, newValue);
|
||||
|
||||
if (callback != null) {
|
||||
try {
|
||||
callback.updateToggleState(config, newValue);
|
||||
callback.updateToggleState(config, newValue != null ? newValue : config.defaultValue);
|
||||
} catch (Exception e) {
|
||||
LogManager.log.severe("[SkeletonConfig] Exception while calling callback", e);
|
||||
}
|
||||
@@ -102,7 +138,7 @@ public class SkeletonConfig {
|
||||
return origVal;
|
||||
}
|
||||
|
||||
public Boolean setToggle(String config, boolean newValue) {
|
||||
public Boolean setToggle(String config, Boolean newValue) {
|
||||
return setToggle(SkeletonConfigToggle.getByStringValue(config), newValue);
|
||||
}
|
||||
|
||||
@@ -189,11 +225,11 @@ public class SkeletonConfig {
|
||||
|
||||
public void setConfigs(Map<SkeletonConfigValue, Float> configs, Map<SkeletonConfigToggle, Boolean> toggles) {
|
||||
if (configs != null) {
|
||||
this.configs.putAll(configs);
|
||||
configs.forEach(this::setConfig);
|
||||
}
|
||||
|
||||
if (toggles != null) {
|
||||
this.toggles.putAll(toggles);
|
||||
toggles.forEach(this::setToggle);
|
||||
}
|
||||
|
||||
if (autoUpdateOffsets) {
|
||||
@@ -204,13 +240,13 @@ public class SkeletonConfig {
|
||||
public void setStringConfigs(Map<String, Float> configs, Map<String, Boolean> toggles) {
|
||||
if (configs != null) {
|
||||
configs.forEach((key, value) -> {
|
||||
this.configs.put(SkeletonConfigValue.getByStringValue(key), value);
|
||||
setConfig(SkeletonConfigValue.getByStringValue(key), value);
|
||||
});
|
||||
}
|
||||
|
||||
if (toggles != null) {
|
||||
toggles.forEach((key, value) -> {
|
||||
this.toggles.put(SkeletonConfigToggle.getByStringValue(key), value);
|
||||
setToggle(SkeletonConfigToggle.getByStringValue(key), value);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -257,14 +293,14 @@ public class SkeletonConfig {
|
||||
for (SkeletonConfigValue configValue : SkeletonConfigValue.values) {
|
||||
Float val = castFloat(config.getProperty(configValue.configKey));
|
||||
if (val != null) {
|
||||
configs.put(configValue, val);
|
||||
setConfig(configValue, val);
|
||||
}
|
||||
}
|
||||
|
||||
for (SkeletonConfigToggle configValue : SkeletonConfigToggle.values) {
|
||||
Boolean val = castBoolean(config.getProperty(configValue.configKey));
|
||||
if (val != null) {
|
||||
toggles.put(configValue, val);
|
||||
setToggle(configValue, val);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,6 +322,9 @@ public class SkeletonConfig {
|
||||
public void resetConfigs() {
|
||||
configs.clear();
|
||||
toggles.clear();
|
||||
|
||||
callCallbackOnAll(false);
|
||||
|
||||
if (autoUpdateOffsets) {
|
||||
computeAllNodeOffsets();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user