-
-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AutoBone: Adjust bone offsets for directly and implement new contribu…
…tion based error calculation (#204)
- Loading branch information
1 parent
d1a02c5
commit b131856
Showing
13 changed files
with
1,120 additions
and
531 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
src/main/java/dev/slimevr/autobone/AutoBoneTrainingStep.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package dev.slimevr.autobone; | ||
|
||
import java.util.Map; | ||
|
||
import dev.slimevr.poserecorder.PoseFrameSkeleton; | ||
import dev.slimevr.poserecorder.PoseFrames; | ||
import dev.slimevr.vr.processor.skeleton.BoneType; | ||
|
||
|
||
public class AutoBoneTrainingStep { | ||
private int cursor1 = 0; | ||
private int cursor2 = 0; | ||
|
||
private float currentHeight; | ||
private final float targetHeight; | ||
|
||
private final PoseFrameSkeleton skeleton1; | ||
private final PoseFrameSkeleton skeleton2; | ||
|
||
private final PoseFrames trainingFrames; | ||
|
||
private final Map<BoneType, Float> intermediateOffsets; | ||
|
||
public AutoBoneTrainingStep( | ||
int cursor1, | ||
int cursor2, | ||
float targetHeight, | ||
PoseFrameSkeleton skeleton1, | ||
PoseFrameSkeleton skeleton2, | ||
PoseFrames trainingFrames, | ||
Map<BoneType, Float> intermediateOffsets | ||
) { | ||
this.cursor1 = cursor1; | ||
this.cursor2 = cursor2; | ||
this.targetHeight = targetHeight; | ||
this.skeleton1 = skeleton1; | ||
this.skeleton2 = skeleton2; | ||
this.trainingFrames = trainingFrames; | ||
this.intermediateOffsets = intermediateOffsets; | ||
} | ||
|
||
public AutoBoneTrainingStep( | ||
float targetHeight, | ||
PoseFrameSkeleton skeleton1, | ||
PoseFrameSkeleton skeleton2, | ||
PoseFrames trainingFrames, | ||
Map<BoneType, Float> intermediateOffsets | ||
) { | ||
this.targetHeight = targetHeight; | ||
this.skeleton1 = skeleton1; | ||
this.skeleton2 = skeleton2; | ||
this.trainingFrames = trainingFrames; | ||
this.intermediateOffsets = intermediateOffsets; | ||
} | ||
|
||
public int getCursor1() { | ||
return cursor1; | ||
} | ||
|
||
public void setCursor1(int cursor1) { | ||
this.cursor1 = cursor1; | ||
} | ||
|
||
public int getCursor2() { | ||
return cursor2; | ||
} | ||
|
||
public void setCursor2(int cursor2) { | ||
this.cursor2 = cursor2; | ||
} | ||
|
||
public void setCursors(int cursor1, int cursor2) { | ||
this.cursor1 = cursor1; | ||
this.cursor2 = cursor2; | ||
} | ||
|
||
public float getCurrentHeight() { | ||
return currentHeight; | ||
} | ||
|
||
public void setCurrentHeight(float currentHeight) { | ||
this.currentHeight = currentHeight; | ||
} | ||
|
||
public float getTargetHeight() { | ||
return targetHeight; | ||
} | ||
|
||
public PoseFrameSkeleton getSkeleton1() { | ||
return skeleton1; | ||
} | ||
|
||
public PoseFrameSkeleton getSkeleton2() { | ||
return skeleton2; | ||
} | ||
|
||
public PoseFrames getTrainingFrames() { | ||
return trainingFrames; | ||
} | ||
|
||
public Map<BoneType, Float> getIntermediateOffsets() { | ||
return intermediateOffsets; | ||
} | ||
|
||
public float getHeightOffset() { | ||
return getTargetHeight() - getCurrentHeight(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/dev/slimevr/autobone/errors/AutoBoneException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package dev.slimevr.autobone.errors; | ||
|
||
public class AutoBoneException extends Exception { | ||
|
||
public AutoBoneException() { | ||
} | ||
|
||
public AutoBoneException(String message) { | ||
super(message); | ||
} | ||
|
||
public AutoBoneException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
public AutoBoneException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public AutoBoneException( | ||
String message, | ||
Throwable cause, | ||
boolean enableSuppression, | ||
boolean writableStackTrace | ||
) { | ||
super(message, cause, enableSuppression, writableStackTrace); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/dev/slimevr/autobone/errors/BodyProportionError.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package dev.slimevr.autobone.errors; | ||
|
||
import com.jme3.math.FastMath; | ||
|
||
import dev.slimevr.autobone.AutoBoneTrainingStep; | ||
import dev.slimevr.vr.processor.skeleton.SkeletonConfig; | ||
import dev.slimevr.vr.processor.skeleton.SkeletonConfigValue; | ||
|
||
|
||
// The distance from average human proportions | ||
public class BodyProportionError implements IAutoBoneError { | ||
|
||
// TODO hip tracker stuff... Hip tracker should be around 3 to 5 | ||
// centimeters. Human average is probably 1.1235 (SD 0.07) | ||
public float legBodyRatio = 1.1235f; | ||
|
||
// SD of 0.07, capture 68% within range | ||
public float legBodyRatioRange = 0.07f; | ||
|
||
// kneeLegRatio seems to be around 0.54 to 0.6 after asking a few people in | ||
// the SlimeVR discord. | ||
public float kneeLegRatio = 0.55f; | ||
|
||
// kneeLegRatio seems to be around 0.55 to 0.64 after asking a few people in | ||
// the SlimeVR discord. TODO : Chest should be a bit shorter (0.54?) if user | ||
// has an additional hip tracker. | ||
public float chestTorsoRatio = 0.57f; | ||
|
||
@Override | ||
public float getStepError(AutoBoneTrainingStep trainingStep) throws AutoBoneException { | ||
return getBodyProportionError(trainingStep.getSkeleton1().skeletonConfig); | ||
} | ||
|
||
public float getBodyProportionError(SkeletonConfig config) { | ||
float neckLength = config.getConfig(SkeletonConfigValue.NECK); | ||
float chestLength = config.getConfig(SkeletonConfigValue.CHEST); | ||
float torsoLength = config.getConfig(SkeletonConfigValue.TORSO); | ||
float legsLength = config.getConfig(SkeletonConfigValue.LEGS_LENGTH); | ||
float kneeHeight = config.getConfig(SkeletonConfigValue.KNEE_HEIGHT); | ||
|
||
float chestTorso = FastMath.abs((chestLength / torsoLength) - chestTorsoRatio); | ||
float legBody = FastMath.abs((legsLength / (torsoLength + neckLength)) - legBodyRatio); | ||
float kneeLeg = FastMath.abs((kneeHeight / legsLength) - kneeLegRatio); | ||
|
||
if (legBody <= legBodyRatioRange) { | ||
legBody = 0f; | ||
} else { | ||
legBody -= legBodyRatioRange; | ||
} | ||
|
||
return (chestTorso + legBody + kneeLeg) / 3f; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/dev/slimevr/autobone/errors/FootHeightOffsetError.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package dev.slimevr.autobone.errors; | ||
|
||
import com.jme3.math.FastMath; | ||
|
||
import dev.slimevr.autobone.AutoBoneTrainingStep; | ||
import dev.slimevr.vr.processor.skeleton.HumanSkeleton; | ||
import dev.slimevr.vr.trackers.ComputedTracker; | ||
import dev.slimevr.vr.trackers.TrackerRole; | ||
|
||
|
||
// The offset between the height both feet at one instant and over time | ||
public class FootHeightOffsetError implements IAutoBoneError { | ||
@Override | ||
public float getStepError(AutoBoneTrainingStep trainingStep) throws AutoBoneException { | ||
return getSlideError(trainingStep.getSkeleton1(), trainingStep.getSkeleton2()); | ||
} | ||
|
||
public static float getSlideError(HumanSkeleton skeleton1, HumanSkeleton skeleton2) { | ||
ComputedTracker leftTracker1 = skeleton1.getComputedTracker(TrackerRole.LEFT_FOOT); | ||
ComputedTracker rightTracker1 = skeleton1.getComputedTracker(TrackerRole.RIGHT_FOOT); | ||
|
||
ComputedTracker leftTracker2 = skeleton2.getComputedTracker(TrackerRole.LEFT_FOOT); | ||
ComputedTracker rightTracker2 = skeleton2.getComputedTracker(TrackerRole.RIGHT_FOOT); | ||
|
||
return getFootHeightError(leftTracker1, rightTracker1, leftTracker2, rightTracker2); | ||
} | ||
|
||
public static float getFootHeightError( | ||
ComputedTracker leftTracker1, | ||
ComputedTracker rightTracker1, | ||
ComputedTracker leftTracker2, | ||
ComputedTracker rightTracker2 | ||
) { | ||
float leftFoot1 = leftTracker1.position.y; | ||
float rightFoot1 = rightTracker1.position.y; | ||
|
||
float leftFoot2 = leftTracker2.position.y; | ||
float rightFoot2 = rightTracker2.position.y; | ||
|
||
// Compute all combinations of heights | ||
float dist1 = FastMath.abs(leftFoot1 - rightFoot1); | ||
float dist2 = FastMath.abs(leftFoot1 - leftFoot2); | ||
float dist3 = FastMath.abs(leftFoot1 - rightFoot2); | ||
|
||
float dist4 = FastMath.abs(rightFoot1 - leftFoot2); | ||
float dist5 = FastMath.abs(rightFoot1 - rightFoot2); | ||
|
||
float dist6 = FastMath.abs(leftFoot2 - rightFoot2); | ||
|
||
// Divide by 12 (6 values * 2 to halve) to halve and average, it's | ||
// halved because you want to approach a midpoint, not the other point | ||
return (dist1 + dist2 + dist3 + dist4 + dist5 + dist6) / 12f; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/dev/slimevr/autobone/errors/HeightError.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package dev.slimevr.autobone.errors; | ||
|
||
import com.jme3.math.FastMath; | ||
|
||
import dev.slimevr.autobone.AutoBoneTrainingStep; | ||
|
||
|
||
// The difference from the current height to the target height | ||
public class HeightError implements IAutoBoneError { | ||
@Override | ||
public float getStepError(AutoBoneTrainingStep trainingStep) throws AutoBoneException { | ||
return getHeightError( | ||
trainingStep.getCurrentHeight(), | ||
trainingStep.getTargetHeight() | ||
); | ||
} | ||
|
||
public float getHeightError(float currentHeight, float targetHeight) { | ||
return FastMath.abs(targetHeight - currentHeight); | ||
} | ||
} |
Oops, something went wrong.