Skip to content

Commit

Permalink
Merge pull request #67 from ButterscotchVanilla/mocap-stuff
Browse files Browse the repository at this point in the history
Add base internal mocap functionality
  • Loading branch information
Eirenliel committed Oct 22, 2021
2 parents 8c356b4 + 820d06f commit 460a42b
Show file tree
Hide file tree
Showing 9 changed files with 463 additions and 107 deletions.
6 changes: 4 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ root = true
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
# This line causes problems with VSCode and potentially with other editors where all purely
# whitespace lines are trimmed to be empty when saved, causing excessive worthless changes with Git
#trim_trailing_whitespace = true
insert_final_newline = true
16 changes: 8 additions & 8 deletions src/main/java/dev/slimevr/autobone/AutoBone.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import com.jme3.math.Vector3f;

import dev.slimevr.poserecorder.PoseFrame;
import dev.slimevr.poserecorder.PoseFrames;
import dev.slimevr.poserecorder.TrackerFrame;
import dev.slimevr.poserecorder.TrackerFrameData;
import io.eiren.util.ann.ThreadSafe;
Expand Down Expand Up @@ -198,7 +198,7 @@ public float getLengthSum(Map<String, Float> configs) {
return length;
}

public float getMaxHmdHeight(PoseFrame frames) {
public float getMaxHmdHeight(PoseFrames frames) {
float maxHeight = 0f;
for(TrackerFrame[] frame : frames) {
TrackerFrame hmd = TrackerUtils.findTrackerForBodyPosition(frame, TrackerPosition.HMD);
Expand All @@ -209,27 +209,27 @@ public float getMaxHmdHeight(PoseFrame frames) {
return maxHeight;
}

public void processFrames(PoseFrame frames) {
public void processFrames(PoseFrames frames) {
processFrames(frames, -1f);
}

public void processFrames(PoseFrame frames, Consumer<Epoch> epochCallback) {
public void processFrames(PoseFrames frames, Consumer<Epoch> epochCallback) {
processFrames(frames, -1f, epochCallback);
}

public void processFrames(PoseFrame frames, float targetHeight) {
public void processFrames(PoseFrames frames, float targetHeight) {
processFrames(frames, true, targetHeight);
}

public void processFrames(PoseFrame frames, float targetHeight, Consumer<Epoch> epochCallback) {
public void processFrames(PoseFrames frames, float targetHeight, Consumer<Epoch> epochCallback) {
processFrames(frames, true, targetHeight, epochCallback);
}

public float processFrames(PoseFrame frames, boolean calcInitError, float targetHeight) {
public float processFrames(PoseFrames frames, boolean calcInitError, float targetHeight) {
return processFrames(frames, calcInitError, targetHeight, null);
}

public float processFrames(PoseFrame frames, boolean calcInitError, float targetHeight, Consumer<Epoch> epochCallback) {
public float processFrames(PoseFrames frames, boolean calcInitError, float targetHeight, Consumer<Epoch> epochCallback) {
final int frameCount = frames.getMaxFrameCount();

final SimpleSkeleton skeleton1 = new SimpleSkeleton(configs, staticConfigs);
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/dev/slimevr/gui/AutoBoneWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import dev.slimevr.autobone.AutoBone;
import dev.slimevr.gui.swing.EJBox;
import dev.slimevr.poserecorder.PoseFrame;
import dev.slimevr.poserecorder.PoseFrames;
import dev.slimevr.poserecorder.PoseFrameIO;
import dev.slimevr.poserecorder.PoseRecorder;

Expand Down Expand Up @@ -82,7 +82,7 @@ private String getLengthsString() {
return configInfo.toString();
}

private void saveRecording(PoseFrame frames) {
private void saveRecording(PoseFrames frames) {
if(saveDir.isDirectory() || saveDir.mkdirs()) {
File saveRecording;
int recordingIndex = 1;
Expand All @@ -101,15 +101,15 @@ private void saveRecording(PoseFrame frames) {
}
}

private List<Pair<String, PoseFrame>> loadRecordings() {
List<Pair<String, PoseFrame>> recordings = new FastList<Pair<String, PoseFrame>>();
private List<Pair<String, PoseFrames>> loadRecordings() {
List<Pair<String, PoseFrames>> recordings = new FastList<Pair<String, PoseFrames>>();
if(loadDir.isDirectory()) {
File[] files = loadDir.listFiles();
if(files != null) {
for(File file : files) {
if(file.isFile() && org.apache.commons.lang3.StringUtils.endsWithIgnoreCase(file.getName(), ".pfr")) {
LogManager.log.info("[AutoBone] Detected recording at \"" + file.getPath() + "\", loading frames...");
PoseFrame frames = PoseFrameIO.readFromFile(file);
PoseFrames frames = PoseFrameIO.readFromFile(file);

if(frames == null) {
LogManager.log.severe("Reading frames from \"" + file.getPath() + "\" failed...");
Expand All @@ -124,7 +124,7 @@ private List<Pair<String, PoseFrame>> loadRecordings() {
return recordings;
}

private float processFrames(PoseFrame frames) {
private float processFrames(PoseFrames frames) {
autoBone.minDataDistance = server.config.getInt("autobone.minimumDataDistance", autoBone.minDataDistance);
autoBone.maxDataDistance = server.config.getInt("autobone.maximumDataDistance", autoBone.maxDataDistance);

Expand Down Expand Up @@ -172,8 +172,8 @@ public void run() {
// 1000 samples at 20 ms per sample is 20 seconds
int sampleCount = server.config.getInt("autobone.sampleCount", 1000);
long sampleRate = server.config.getLong("autobone.sampleRateMs", 20L);
Future<PoseFrame> framesFuture = poseRecorder.startFrameRecording(sampleCount, sampleRate);
PoseFrame frames = framesFuture.get();
Future<PoseFrames> framesFuture = poseRecorder.startFrameRecording(sampleCount, sampleRate);
PoseFrames frames = framesFuture.get();
LogManager.log.info("[AutoBone] Done recording!");

saveRecordingButton.setEnabled(true);
Expand Down Expand Up @@ -226,10 +226,10 @@ public void mouseClicked(MouseEvent e) {
@Override
public void run() {
try {
Future<PoseFrame> framesFuture = poseRecorder.getFramesAsync();
Future<PoseFrames> framesFuture = poseRecorder.getFramesAsync();
if(framesFuture != null) {
setText("Waiting for Recording...");
PoseFrame frames = framesFuture.get();
PoseFrames frames = framesFuture.get();

if(frames.getTrackerCount() <= 0) {
throw new IllegalStateException("Recording has no trackers");
Expand Down Expand Up @@ -297,15 +297,15 @@ public void mouseClicked(MouseEvent e) {
public void run() {
try {
setText("Load...");
List<Pair<String, PoseFrame>> frameRecordings = loadRecordings();
List<Pair<String, PoseFrames>> frameRecordings = loadRecordings();

if(!frameRecordings.isEmpty()) {
LogManager.log.info("[AutoBone] Done loading frames!");
} else {
Future<PoseFrame> framesFuture = poseRecorder.getFramesAsync();
Future<PoseFrames> framesFuture = poseRecorder.getFramesAsync();
if(framesFuture != null) {
setText("Waiting for Recording...");
PoseFrame frames = framesFuture.get();
PoseFrames frames = framesFuture.get();

if(frames.getTrackerCount() <= 0) {
throw new IllegalStateException("Recording has no trackers");
Expand All @@ -331,7 +331,7 @@ public void run() {
setText("Processing...");
LogManager.log.info("[AutoBone] Processing frames...");
FastList<Float> heightPercentError = new FastList<Float>(frameRecordings.size());
for(Pair<String, PoseFrame> recording : frameRecordings) {
for(Pair<String, PoseFrames> recording : frameRecordings) {
LogManager.log.info("[AutoBone] Processing frames from \"" + recording.getKey() + "\"...");

heightPercentError.add(processFrames(recording.getValue()));
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/dev/slimevr/poserecorder/PoseFrameIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private PoseFrameIO() {
// Do not allow instantiating
}

public static boolean writeFrames(DataOutputStream outputStream, PoseFrame frames) {
public static boolean writeFrames(DataOutputStream outputStream, PoseFrames frames) {
try {
if(frames != null) {
outputStream.writeInt(frames.getTrackerCount());
Expand Down Expand Up @@ -67,7 +67,7 @@ public static boolean writeFrames(DataOutputStream outputStream, PoseFrame frame
return true;
}

public static boolean writeToFile(File file, PoseFrame frames) {
public static boolean writeToFile(File file, PoseFrames frames) {
try(DataOutputStream outputStream = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)))) {
writeFrames(outputStream, frames);
} catch(Exception e) {
Expand All @@ -78,7 +78,7 @@ public static boolean writeToFile(File file, PoseFrame frames) {
return true;
}

public static PoseFrame readFrames(DataInputStream inputStream) {
public static PoseFrames readFrames(DataInputStream inputStream) {
try {

int trackerCount = inputStream.readInt();
Expand Down Expand Up @@ -119,15 +119,15 @@ public static PoseFrame readFrames(DataInputStream inputStream) {
trackers.add(new PoseFrameTracker(name, trackerFrames));
}

return new PoseFrame(trackers);
return new PoseFrames(trackers);
} catch(Exception e) {
LogManager.log.severe("Error reading frame from stream", e);
}

return null;
}

public static PoseFrame readFromFile(File file) {
public static PoseFrames readFromFile(File file) {
try {
return readFrames(new DataInputStream(new BufferedInputStream(new FileInputStream(file))));
} catch(Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
import io.eiren.util.collections.FastList;
import io.eiren.vr.trackers.Tracker;

public final class PoseFrame implements Iterable<TrackerFrame[]> {
public final class PoseFrames implements Iterable<TrackerFrame[]> {

private final FastList<PoseFrameTracker> trackers;

public PoseFrame(FastList<PoseFrameTracker> trackers) {
public PoseFrames(FastList<PoseFrameTracker> trackers) {
this.trackers = trackers;
}

public PoseFrame(int initialCapacity) {
public PoseFrames(int initialCapacity) {
this.trackers = new FastList<PoseFrameTracker>(initialCapacity);
}

public PoseFrame() {
public PoseFrames() {
this(5);
}

Expand Down Expand Up @@ -103,12 +103,12 @@ public Iterator<TrackerFrame[]> iterator() {

public class PoseFrameIterator implements Iterator<TrackerFrame[]> {

private final PoseFrame poseFrame;
private final PoseFrames poseFrame;
private final TrackerFrame[] trackerFrameBuffer;

private int cursor = 0;

public PoseFrameIterator(PoseFrame poseFrame) {
public PoseFrameIterator(PoseFrames poseFrame) {
this.poseFrame = poseFrame;
trackerFrameBuffer = new TrackerFrame[poseFrame.getTrackerCount()];
}
Expand Down
Loading

0 comments on commit 460a42b

Please sign in to comment.