mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-28 12:56:32 -08:00
Change namespaces, change PoseRecorder format, use TrackerBodyPosition for designation
This commit is contained in:
10 files changed
+343
-174
No files matched your search
+16
-3
@@ -1,4 +1,4 @@
|
||||
package io.eiren.gui.autobone;
|
||||
package dev.slimevr.gui;
|
||||
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JFrame;
|
||||
@@ -20,10 +20,16 @@ import io.eiren.util.ann.AWTThread;
|
||||
import io.eiren.util.collections.FastList;
|
||||
import io.eiren.util.logging.LogManager;
|
||||
import io.eiren.vr.VRServer;
|
||||
import dev.slimevr.vr.autobone.AutoBone;
|
||||
|
||||
import javax.swing.event.MouseInputAdapter;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import dev.slimevr.vr.poserecorder.PoseFrame;
|
||||
import dev.slimevr.vr.poserecorder.PoseFrameIO;
|
||||
import dev.slimevr.vr.poserecorder.PoseRecorder;
|
||||
|
||||
public class AutoBoneWindow extends JFrame {
|
||||
|
||||
private static File saveDir = new File("Recordings");
|
||||
@@ -82,7 +88,7 @@ public class AutoBoneWindow extends JFrame {
|
||||
File saveRecording;
|
||||
int recordingIndex = 1;
|
||||
do {
|
||||
saveRecording = new File(saveDir, "ABRecording" + recordingIndex++ + ".abf");
|
||||
saveRecording = new File(saveDir, "ABRecording" + recordingIndex++ + ".pfr");
|
||||
} while (saveRecording.exists());
|
||||
|
||||
LogManager.log.info("[AutoBone] Exporting frames to \"" + saveRecording.getPath() + "\"...");
|
||||
@@ -102,7 +108,7 @@ public class AutoBoneWindow extends JFrame {
|
||||
File[] files = loadDir.listFiles();
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
if (file.isFile() && org.apache.commons.lang3.StringUtils.endsWithIgnoreCase(file.getName(), ".abf")) {
|
||||
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);
|
||||
|
||||
@@ -230,6 +236,13 @@ public class AutoBoneWindow extends JFrame {
|
||||
|
||||
setText("Saving...");
|
||||
saveRecording(frames);
|
||||
|
||||
setText("Recording Saved!");
|
||||
try {
|
||||
Thread.sleep(3000); // Wait for 3 seconds
|
||||
} catch (Exception e1) {
|
||||
// Ignore
|
||||
}
|
||||
} else {
|
||||
setText("No Recording...");
|
||||
LogManager.log.severe("[AutoBone] Unable to save, no recording was done...");
|
||||
+54
-40
@@ -1,4 +1,4 @@
|
||||
package io.eiren.gui.autobone;
|
||||
package dev.slimevr.vr.autobone;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -7,10 +7,13 @@ import java.util.function.Consumer;
|
||||
|
||||
import com.jme3.math.Vector3f;
|
||||
|
||||
import dev.slimevr.vr.poserecorder.PoseFrame;
|
||||
import dev.slimevr.vr.poserecorder.TrackerFrameData;
|
||||
import io.eiren.util.ann.ThreadSafe;
|
||||
import io.eiren.util.logging.LogManager;
|
||||
import io.eiren.util.collections.FastList;
|
||||
import io.eiren.vr.VRServer;
|
||||
import dev.slimevr.vr.poserecorder.TrackerFrame;
|
||||
import io.eiren.vr.processor.HumanSkeleton;
|
||||
import io.eiren.vr.processor.HumanSkeletonWithLegs;
|
||||
import io.eiren.vr.processor.HumanSkeletonWithWaist;
|
||||
@@ -200,8 +203,9 @@ public class AutoBone {
|
||||
public float getMaxHmdHeight(PoseFrame[] frames) {
|
||||
float maxHeight = 0f;
|
||||
for (PoseFrame frame : frames) {
|
||||
if (frame.rootPos.y > maxHeight) {
|
||||
maxHeight = frame.rootPos.y;
|
||||
TrackerFrame hmd = frame.trackerFrames.get(TrackerBodyPosition.HMD);
|
||||
if (hmd != null && hmd.hasData(TrackerFrameData.POSITION) && hmd.position.y > maxHeight) {
|
||||
maxHeight = hmd.position.y;
|
||||
}
|
||||
}
|
||||
return maxHeight;
|
||||
@@ -356,8 +360,8 @@ public class AutoBone {
|
||||
|
||||
// The change in position of the ankle over time
|
||||
protected float getSlideErrorDeriv(SimpleSkeleton skeleton1, SimpleSkeleton skeleton2) {
|
||||
float slideLeft = skeleton1.getLeftFootPos().distance(skeleton2.getLeftFootPos());
|
||||
float slideRight = skeleton1.getRightFootPos().distance(skeleton2.getRightFootPos());
|
||||
float slideLeft = skeleton1.getNodePosition(TrackerBodyPosition.LEFT_ANKLE).distance(skeleton2.getNodePosition(TrackerBodyPosition.LEFT_ANKLE));
|
||||
float slideRight = skeleton1.getNodePosition(TrackerBodyPosition.RIGHT_ANKLE).distance(skeleton2.getNodePosition(TrackerBodyPosition.RIGHT_ANKLE));
|
||||
|
||||
// Divide by 4 to halve and average, it's halved because you want to approach a midpoint, not the other point
|
||||
return (slideLeft + slideRight) / 4f;
|
||||
@@ -365,14 +369,20 @@ public class AutoBone {
|
||||
|
||||
// The offset between both feet at one instant and over time
|
||||
protected float getOffsetErrorDeriv(SimpleSkeleton skeleton1, SimpleSkeleton skeleton2) {
|
||||
float dist1 = Math.abs(skeleton1.getLeftFootPos().y - skeleton1.getRightFootPos().y);
|
||||
float dist2 = Math.abs(skeleton2.getLeftFootPos().y - skeleton2.getRightFootPos().y);
|
||||
float skeleton1Left = skeleton1.getNodePosition(TrackerBodyPosition.LEFT_ANKLE).getY();
|
||||
float skeleton1Right = skeleton1.getNodePosition(TrackerBodyPosition.RIGHT_ANKLE).getY();
|
||||
|
||||
float dist3 = Math.abs(skeleton1.getLeftFootPos().y - skeleton2.getRightFootPos().y);
|
||||
float dist4 = Math.abs(skeleton1.getLeftFootPos().y - skeleton2.getRightFootPos().y);
|
||||
float skeleton2Left = skeleton2.getNodePosition(TrackerBodyPosition.LEFT_ANKLE).getY();
|
||||
float skeleton2Right = skeleton2.getNodePosition(TrackerBodyPosition.RIGHT_ANKLE).getY();
|
||||
|
||||
float dist5 = Math.abs(skeleton1.getLeftFootPos().y - skeleton2.getLeftFootPos().y);
|
||||
float dist6 = Math.abs(skeleton1.getRightFootPos().y - skeleton2.getRightFootPos().y);
|
||||
float dist1 = Math.abs(skeleton1Left - skeleton1Right);
|
||||
float dist2 = Math.abs(skeleton2Left - skeleton2Right);
|
||||
|
||||
float dist3 = Math.abs(skeleton1Left - skeleton2Right);
|
||||
float dist4 = Math.abs(skeleton2Left - skeleton1Right);
|
||||
|
||||
float dist5 = Math.abs(skeleton1Left - skeleton2Left);
|
||||
float dist6 = Math.abs(skeleton1Right - skeleton2Right);
|
||||
|
||||
// Divide by 12 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;
|
||||
@@ -404,13 +414,15 @@ public class AutoBone {
|
||||
float offset = 0f;
|
||||
int offsetCount = 0;
|
||||
|
||||
if (frame.positions != null) {
|
||||
for (Entry<String, Vector3f> entry : frame.positions.entrySet()) {
|
||||
Vector3f nodePos = skeleton.getNodePosition(entry.getKey());
|
||||
if (nodePos != null) {
|
||||
offset += Math.abs(nodePos.distance(entry.getValue()));
|
||||
offsetCount++;
|
||||
}
|
||||
for (TrackerFrame trackerFrame : frame.trackerFrames.values()) {
|
||||
if (!trackerFrame.hasData(TrackerFrameData.POSITION)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Vector3f nodePos = skeleton.getNodePosition(trackerFrame.designation.designation);
|
||||
if (nodePos != null) {
|
||||
offset += Math.abs(nodePos.distance(trackerFrame.position));
|
||||
offsetCount++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -422,29 +434,31 @@ public class AutoBone {
|
||||
float offset = 0f;
|
||||
int offsetCount = 0;
|
||||
|
||||
if (frame1.positions != null && frame2.positions != null) {
|
||||
for (Entry<String, Vector3f> entry : frame1.positions.entrySet()) {
|
||||
Vector3f frame2Pos = frame2.positions.get(entry.getKey());
|
||||
if (frame2Pos == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Vector3f nodePos1 = skeleton1.getNodePosition(entry.getKey());
|
||||
if (nodePos1 == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Vector3f nodePos2 = skeleton2.getNodePosition(entry.getKey());
|
||||
if (nodePos2 == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
float dist1 = Math.abs(nodePos1.distance(entry.getValue()));
|
||||
float dist2 = Math.abs(nodePos2.distance(frame2Pos));
|
||||
|
||||
offset += Math.abs(dist2 - dist1);
|
||||
offsetCount++;
|
||||
for (TrackerFrame trackerFrame1 : frame1.trackerFrames.values()) {
|
||||
if (!trackerFrame1.hasData(TrackerFrameData.POSITION)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
TrackerFrame trackerFrame2 = frame2.trackerFrames.get(trackerFrame1.designation);
|
||||
if (trackerFrame2 == null || !trackerFrame2.hasData(TrackerFrameData.POSITION)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Vector3f nodePos1 = skeleton1.getNodePosition(trackerFrame1.designation);
|
||||
if (nodePos1 == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Vector3f nodePos2 = skeleton2.getNodePosition(trackerFrame2.designation);
|
||||
if (nodePos2 == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
float dist1 = Math.abs(nodePos1.distance(trackerFrame1.position));
|
||||
float dist2 = Math.abs(nodePos2.distance(trackerFrame2.position));
|
||||
|
||||
offset += Math.abs(dist2 - dist1);
|
||||
offsetCount++;
|
||||
}
|
||||
|
||||
return offsetCount > 0 ? offset / offsetCount : 0f;
|
||||
+60
-39
@@ -1,14 +1,17 @@
|
||||
package io.eiren.gui.autobone;
|
||||
package dev.slimevr.vr.autobone;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.jme3.math.Quaternion;
|
||||
import com.jme3.math.Vector3f;
|
||||
|
||||
import dev.slimevr.vr.poserecorder.PoseFrame;
|
||||
import dev.slimevr.vr.poserecorder.TrackerFrameData;
|
||||
import dev.slimevr.vr.poserecorder.TrackerFrame;
|
||||
import io.eiren.vr.processor.HumanSkeletonWithLegs;
|
||||
import io.eiren.vr.processor.HumanSkeletonWithWaist;
|
||||
import io.eiren.vr.processor.TrackerBodyPosition;
|
||||
import io.eiren.vr.processor.TransformNode;
|
||||
import io.eiren.yaml.YamlFile;
|
||||
|
||||
@@ -121,35 +124,18 @@ public class SimpleSkeleton {
|
||||
this(configs.entrySet());
|
||||
}
|
||||
|
||||
public void setPoseFromSkeleton(HumanSkeletonWithLegs humanSkeleton) {
|
||||
TransformNode rootNode = humanSkeleton.getRootNode();
|
||||
|
||||
// Copy headset position
|
||||
hmdNode.localTransform.setTranslation(rootNode.localTransform.getTranslation());
|
||||
|
||||
// Copy all rotations
|
||||
rootNode.depthFirstTraversal(visitor -> {
|
||||
TransformNode targetNode = nodes.get(visitor.getName());
|
||||
|
||||
// Handle unexpected nodes gracefully
|
||||
if (targetNode != null) {
|
||||
targetNode.localTransform.setRotation(visitor.localTransform.getRotation());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setPoseFromFrame(PoseFrame frame) {
|
||||
// Copy headset position
|
||||
hmdNode.localTransform.setTranslation(frame.rootPos);
|
||||
for (TrackerFrame trackerFrame : frame.trackerFrames.values()) {
|
||||
// Set HMD position
|
||||
if (trackerFrame.designation == TrackerBodyPosition.HMD && trackerFrame.hasData(TrackerFrameData.POSITION)) {
|
||||
hmdNode.localTransform.setTranslation(trackerFrame.position);
|
||||
}
|
||||
|
||||
if (frame.rotations != null) {
|
||||
// Copy all rotations
|
||||
for (Entry<String, Quaternion> rotation : frame.rotations.entrySet()) {
|
||||
TransformNode targetNode = nodes.get(rotation.getKey());
|
||||
|
||||
// Handle unexpected nodes gracefully
|
||||
if (targetNode != null) {
|
||||
targetNode.localTransform.setRotation(rotation.getValue());
|
||||
// Set joint rotations
|
||||
if (trackerFrame.hasData(TrackerFrameData.ROTATION)) {
|
||||
TransformNode node = getNode(trackerFrame.designation, true);
|
||||
if (node != null) {
|
||||
node.localTransform.setRotation(trackerFrame.rotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -256,24 +242,59 @@ public class SimpleSkeleton {
|
||||
}
|
||||
|
||||
public void updatePose() {
|
||||
// Rotate hips with waist
|
||||
waistNode.localTransform.setRotation(chestNode.localTransform.getRotation());
|
||||
hmdNode.update();
|
||||
}
|
||||
|
||||
public Vector3f getNodePosition(String node) {
|
||||
public TransformNode getNode(String node) {
|
||||
TransformNode transformNode = nodes.get(node);
|
||||
return transformNode;
|
||||
}
|
||||
|
||||
public TransformNode getNode(TrackerBodyPosition bodyPosition) {
|
||||
return getNode(bodyPosition, false);
|
||||
}
|
||||
|
||||
public TransformNode getNode(TrackerBodyPosition bodyPosition, boolean rotationNode) {
|
||||
if (bodyPosition == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
switch (bodyPosition) {
|
||||
case HMD:
|
||||
return hmdNode;
|
||||
case CHEST:
|
||||
return rotationNode ? neckNode : chestNode;
|
||||
case WAIST:
|
||||
return rotationNode ? chestNode : waistNode;
|
||||
|
||||
case LEFT_LEG:
|
||||
return rotationNode ? leftHipNode : leftKneeNode;
|
||||
case RIGHT_LEG:
|
||||
return rotationNode ? rightHipNode : rightKneeNode;
|
||||
|
||||
case LEFT_ANKLE:
|
||||
return rotationNode ? leftKneeNode : leftAnkleNode;
|
||||
case RIGHT_ANKLE:
|
||||
return rotationNode ? rightKneeNode : rightAnkleNode;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Vector3f getNodePosition(String node) {
|
||||
TransformNode transformNode = getNode(node);
|
||||
return transformNode != null ? transformNode.worldTransform.getTranslation() : null;
|
||||
}
|
||||
|
||||
public Vector3f getHMDPos() {
|
||||
return hmdNode.worldTransform.getTranslation();
|
||||
}
|
||||
public Vector3f getNodePosition(TrackerBodyPosition bodyPosition) {
|
||||
TransformNode node = getNode(bodyPosition);
|
||||
if (node == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Vector3f getLeftFootPos() {
|
||||
return leftAnkleNode.worldTransform.getTranslation();
|
||||
}
|
||||
|
||||
public Vector3f getRightFootPos() {
|
||||
return rightAnkleNode.worldTransform.getTranslation();
|
||||
return node.worldTransform.getTranslation();
|
||||
}
|
||||
|
||||
public void saveConfigs(YamlFile config) {
|
||||
@@ -0,0 +1,44 @@
|
||||
package dev.slimevr.vr.poserecorder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import io.eiren.vr.processor.TrackerBodyPosition;
|
||||
import io.eiren.vr.trackers.Tracker;
|
||||
|
||||
public final class PoseFrame {
|
||||
|
||||
public final HashMap<TrackerBodyPosition, TrackerFrame> trackerFrames;
|
||||
|
||||
public PoseFrame(HashMap<TrackerBodyPosition, TrackerFrame> trackerFrames) {
|
||||
this.trackerFrames = trackerFrames;
|
||||
}
|
||||
|
||||
public PoseFrame(List<TrackerFrame> trackerFrames) {
|
||||
HashMap<TrackerBodyPosition, TrackerFrame> trackerFramesMap = new HashMap<TrackerBodyPosition, TrackerFrame>(trackerFrames.size());
|
||||
|
||||
for (TrackerFrame trackerFrame : trackerFrames) {
|
||||
trackerFramesMap.put(trackerFrame.designation, trackerFrame);
|
||||
}
|
||||
|
||||
this.trackerFrames = trackerFramesMap;
|
||||
}
|
||||
|
||||
public static PoseFrame fromTrackers(List<Tracker> trackers) {
|
||||
if (trackers == null || trackers.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
HashMap<TrackerBodyPosition, TrackerFrame> trackerFrames = new HashMap<TrackerBodyPosition, TrackerFrame>(trackers.size());
|
||||
|
||||
for (Tracker tracker : trackers) {
|
||||
TrackerFrame trackerFrame = TrackerFrame.fromTracker(tracker);
|
||||
|
||||
if (trackerFrame != null) {
|
||||
trackerFrames.put(trackerFrame.designation, trackerFrame);
|
||||
}
|
||||
}
|
||||
|
||||
return new PoseFrame(trackerFrames);
|
||||
}
|
||||
}
|
||||
+61
-34
@@ -1,4 +1,4 @@
|
||||
package io.eiren.gui.autobone;
|
||||
package dev.slimevr.vr.poserecorder;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
@@ -7,13 +7,14 @@ import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.List;
|
||||
|
||||
import com.jme3.math.Quaternion;
|
||||
import com.jme3.math.Vector3f;
|
||||
|
||||
import io.eiren.util.collections.FastList;
|
||||
import io.eiren.util.logging.LogManager;
|
||||
import io.eiren.vr.processor.TrackerBodyPosition;
|
||||
|
||||
public final class PoseFrameIO {
|
||||
|
||||
@@ -38,41 +39,28 @@ public final class PoseFrameIO {
|
||||
|
||||
public static boolean writeFrame(DataOutputStream outputStream, PoseFrame frame) {
|
||||
try {
|
||||
// Write root position vector
|
||||
outputStream.writeFloat(frame.rootPos.x);
|
||||
outputStream.writeFloat(frame.rootPos.y);
|
||||
outputStream.writeFloat(frame.rootPos.z);
|
||||
if (frame != null && frame.trackerFrames != null) {
|
||||
outputStream.writeInt(frame.trackerFrames.size());
|
||||
|
||||
if (frame.rotations != null) {
|
||||
// Write rotations
|
||||
outputStream.writeInt(frame.rotations.size());
|
||||
for (Entry<String, Quaternion> entry : frame.rotations.entrySet()) {
|
||||
// Write the label string
|
||||
outputStream.writeUTF(entry.getKey());
|
||||
for (TrackerFrame trackerFrame : frame.trackerFrames.values()) {
|
||||
outputStream.writeInt(trackerFrame.getDataFlags());
|
||||
|
||||
// Write the rotation quaternion
|
||||
Quaternion quat = entry.getValue();
|
||||
outputStream.writeFloat(quat.getX());
|
||||
outputStream.writeFloat(quat.getY());
|
||||
outputStream.writeFloat(quat.getZ());
|
||||
outputStream.writeFloat(quat.getW());
|
||||
}
|
||||
} else {
|
||||
outputStream.writeInt(0);
|
||||
}
|
||||
if (trackerFrame.hasData(TrackerFrameData.DESIGNATION)) {
|
||||
outputStream.writeUTF(trackerFrame.designation.designation);
|
||||
}
|
||||
|
||||
if (frame.positions != null) {
|
||||
// Write positions
|
||||
outputStream.writeInt(frame.positions.size());
|
||||
for (Entry<String, Vector3f> entry : frame.positions.entrySet()) {
|
||||
// Write the label string
|
||||
outputStream.writeUTF(entry.getKey());
|
||||
if (trackerFrame.hasData(TrackerFrameData.ROTATION)) {
|
||||
outputStream.writeFloat(trackerFrame.rotation.getX());
|
||||
outputStream.writeFloat(trackerFrame.rotation.getY());
|
||||
outputStream.writeFloat(trackerFrame.rotation.getZ());
|
||||
outputStream.writeFloat(trackerFrame.rotation.getW());
|
||||
}
|
||||
|
||||
// Write the rotation quaternion
|
||||
Vector3f vec = entry.getValue();
|
||||
outputStream.writeFloat(vec.getX());
|
||||
outputStream.writeFloat(vec.getY());
|
||||
outputStream.writeFloat(vec.getZ());
|
||||
if (trackerFrame.hasData(TrackerFrameData.POSITION)) {
|
||||
outputStream.writeFloat(trackerFrame.position.getX());
|
||||
outputStream.writeFloat(trackerFrame.position.getY());
|
||||
outputStream.writeFloat(trackerFrame.position.getZ());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
outputStream.writeInt(0);
|
||||
@@ -115,6 +103,7 @@ public final class PoseFrameIO {
|
||||
|
||||
public static PoseFrame readFrame(DataInputStream inputStream) {
|
||||
try {
|
||||
/*
|
||||
float vecX = inputStream.readFloat();
|
||||
float vecY = inputStream.readFloat();
|
||||
float vecZ = inputStream.readFloat();
|
||||
@@ -155,6 +144,44 @@ public final class PoseFrameIO {
|
||||
}
|
||||
|
||||
return new PoseFrame(vector, rotations, positions);
|
||||
*/
|
||||
|
||||
int trackerFrameCount = inputStream.readInt();
|
||||
if (trackerFrameCount > 0) {
|
||||
List<TrackerFrame> trackerFrames = new FastList<TrackerFrame>(trackerFrameCount);
|
||||
|
||||
for (int i = 0; i < trackerFrameCount; i++) {
|
||||
int dataFlags = inputStream.readInt();
|
||||
|
||||
TrackerBodyPosition designation = null;
|
||||
if (TrackerFrameData.DESIGNATION.check(dataFlags)) {
|
||||
designation = TrackerBodyPosition.getByDesignation(inputStream.readUTF());
|
||||
}
|
||||
|
||||
Quaternion rotation = null;
|
||||
if (TrackerFrameData.ROTATION.check(dataFlags)) {
|
||||
float quatX = inputStream.readFloat();
|
||||
float quatY = inputStream.readFloat();
|
||||
float quatZ = inputStream.readFloat();
|
||||
float quatW = inputStream.readFloat();
|
||||
rotation = new Quaternion(quatX, quatY, quatZ, quatW);
|
||||
}
|
||||
|
||||
Vector3f position = null;
|
||||
if (TrackerFrameData.POSITION.check(dataFlags)) {
|
||||
float posX = inputStream.readFloat();
|
||||
float posY = inputStream.readFloat();
|
||||
float posZ = inputStream.readFloat();
|
||||
position = new Vector3f(posX, posY, posZ);
|
||||
}
|
||||
|
||||
trackerFrames.add(new TrackerFrame(designation, rotation, position));
|
||||
}
|
||||
|
||||
return new PoseFrame(trackerFrames);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogManager.log.severe("Error reading frame from stream", e);
|
||||
}
|
||||
+20
-20
@@ -1,16 +1,15 @@
|
||||
package io.eiren.gui.autobone;
|
||||
package dev.slimevr.vr.poserecorder;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import io.eiren.util.ann.ThreadSafe;
|
||||
import io.eiren.util.ann.VRServerThread;
|
||||
import io.eiren.util.collections.FastList;
|
||||
import io.eiren.util.logging.LogManager;
|
||||
import io.eiren.vr.VRServer;
|
||||
import io.eiren.vr.processor.HumanSkeleton;
|
||||
import io.eiren.vr.processor.HumanSkeletonWithLegs;
|
||||
import io.eiren.vr.trackers.Tracker;
|
||||
|
||||
public class PoseRecorder {
|
||||
|
||||
@@ -23,44 +22,42 @@ public class PoseRecorder {
|
||||
protected CompletableFuture<PoseFrame[]> currentRecording;
|
||||
|
||||
protected final VRServer server;
|
||||
HumanSkeletonWithLegs skeleton = null;
|
||||
List<Tracker> trackers = null;
|
||||
|
||||
public PoseRecorder(VRServer server) {
|
||||
this.server = server;
|
||||
server.addOnTick(this::onTick);
|
||||
server.addSkeletonUpdatedCallback(this::skeletonUpdated);
|
||||
}
|
||||
|
||||
@VRServerThread
|
||||
public void onTick() {
|
||||
if (numFrames > 0) {
|
||||
HumanSkeletonWithLegs skeleton = this.skeleton;
|
||||
if (skeleton != null) {
|
||||
List<Tracker> trackers = this.trackers;
|
||||
if (trackers != null) {
|
||||
if (frames.size() < numFrames) {
|
||||
if (System.currentTimeMillis() >= nextFrameTimeMs) {
|
||||
nextFrameTimeMs = System.currentTimeMillis() + frameRecordingInterval;
|
||||
frames.add(new PoseFrame(skeleton));
|
||||
PoseFrame frame = PoseFrame.fromTrackers(trackers);
|
||||
|
||||
// If done, send finished recording
|
||||
if (frames.size() >= numFrames) {
|
||||
internalStopRecording();
|
||||
if (frame != null) {
|
||||
frames.add(frame);
|
||||
|
||||
// If done, send finished recording
|
||||
if (frames.size() >= numFrames) {
|
||||
internalStopRecording();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// If done and hasn't yet, send finished recording
|
||||
internalStopRecording();
|
||||
}
|
||||
} else {
|
||||
this.trackers = server.getAllTrackers();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ThreadSafe
|
||||
public void skeletonUpdated(HumanSkeleton newSkeleton) {
|
||||
if (newSkeleton instanceof HumanSkeletonWithLegs) {
|
||||
skeleton = (HumanSkeletonWithLegs) newSkeleton;
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized Future<PoseFrame[]> startFrameRecording(int numFrames, long interval) {
|
||||
if (numFrames < 1) {
|
||||
throw new IllegalArgumentException("numFrames must at least have a value of 1");
|
||||
@@ -74,6 +71,9 @@ public class PoseRecorder {
|
||||
|
||||
cancelFrameRecording();
|
||||
|
||||
// Update tracker list
|
||||
this.trackers = server.getAllTrackers();
|
||||
|
||||
// Clear old frames and ensure new size can be held
|
||||
frames.clear();
|
||||
frames.ensureCapacity(numFrames);
|
||||
@@ -114,7 +114,7 @@ public class PoseRecorder {
|
||||
}
|
||||
|
||||
public boolean isReadyToRecord() {
|
||||
return skeleton != null;
|
||||
return server.getTrackersCount() > 0;
|
||||
}
|
||||
|
||||
public boolean isRecording() {
|
||||
@@ -0,0 +1,70 @@
|
||||
package dev.slimevr.vr.poserecorder;
|
||||
|
||||
import com.jme3.math.Quaternion;
|
||||
import com.jme3.math.Vector3f;
|
||||
|
||||
import io.eiren.vr.processor.TrackerBodyPosition;
|
||||
import io.eiren.vr.trackers.Tracker;
|
||||
|
||||
public final class TrackerFrame {
|
||||
|
||||
private int dataFlags = 0;
|
||||
|
||||
public final TrackerBodyPosition designation;
|
||||
public final Quaternion rotation;
|
||||
public final Vector3f position;
|
||||
|
||||
public TrackerFrame(TrackerBodyPosition designation, Quaternion rotation, Vector3f position) {
|
||||
this.designation = designation;
|
||||
if (designation != null) {
|
||||
dataFlags |= TrackerFrameData.DESIGNATION.flag;
|
||||
}
|
||||
|
||||
this.rotation = rotation;
|
||||
if (rotation != null) {
|
||||
dataFlags |= TrackerFrameData.ROTATION.flag;
|
||||
}
|
||||
|
||||
this.position = position;
|
||||
if (position != null) {
|
||||
dataFlags |= TrackerFrameData.POSITION.flag;
|
||||
}
|
||||
}
|
||||
|
||||
public TrackerFrame(TrackerBodyPosition designation, Quaternion rotation) {
|
||||
this(designation, rotation, null);
|
||||
}
|
||||
|
||||
public TrackerFrame(TrackerBodyPosition designation, Vector3f position) {
|
||||
this(designation, null, position);
|
||||
}
|
||||
|
||||
public static TrackerFrame fromTracker(Tracker tracker) {
|
||||
// If null or has no data
|
||||
if (tracker == null || (!tracker.hasRotation() && !tracker.hasPosition())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Quaternion rotation = null;
|
||||
if (tracker.hasRotation()) {
|
||||
rotation = new Quaternion();
|
||||
tracker.getRotation(rotation);
|
||||
}
|
||||
|
||||
Vector3f position = null;
|
||||
if (tracker.hasPosition()) {
|
||||
position = new Vector3f();
|
||||
tracker.getPosition(position);
|
||||
}
|
||||
|
||||
return new TrackerFrame(tracker.getBodyPosition(), rotation, position);
|
||||
}
|
||||
|
||||
public int getDataFlags() {
|
||||
return dataFlags;
|
||||
}
|
||||
|
||||
public boolean hasData(TrackerFrameData flag) {
|
||||
return flag.check(dataFlags);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package dev.slimevr.vr.poserecorder;
|
||||
|
||||
public enum TrackerFrameData {
|
||||
DESIGNATION(0),
|
||||
ROTATION(1),
|
||||
POSITION(2);
|
||||
|
||||
public final int flag;
|
||||
|
||||
TrackerFrameData(int id) {
|
||||
this.flag = 1 << id;
|
||||
}
|
||||
|
||||
public boolean check(int dataFlags) {
|
||||
return (dataFlags & this.flag) != 0;
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import javax.swing.JCheckBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.event.MouseInputAdapter;
|
||||
|
||||
import io.eiren.gui.autobone.AutoBoneWindow;
|
||||
import dev.slimevr.gui.AutoBoneWindow;
|
||||
import io.eiren.util.StringUtils;
|
||||
import io.eiren.util.ann.ThreadSafe;
|
||||
import io.eiren.vr.VRServer;
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
package io.eiren.gui.autobone;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.jme3.math.Quaternion;
|
||||
import com.jme3.math.Vector3f;
|
||||
|
||||
import io.eiren.vr.processor.HumanSkeletonWithLegs;
|
||||
import io.eiren.vr.processor.TransformNode;
|
||||
|
||||
public final class PoseFrame {
|
||||
|
||||
public final Vector3f rootPos;
|
||||
public final HashMap<String, Quaternion> rotations;
|
||||
public final HashMap<String, Vector3f> positions;
|
||||
|
||||
public PoseFrame(Vector3f rootPos, HashMap<String, Quaternion> rotations, HashMap<String, Vector3f> positions) {
|
||||
this.rootPos = rootPos;
|
||||
this.rotations = rotations;
|
||||
this.positions = positions;
|
||||
}
|
||||
|
||||
public PoseFrame(HumanSkeletonWithLegs skeleton) {
|
||||
// Copy headset position
|
||||
TransformNode rootNode = skeleton.getRootNode();
|
||||
this.rootPos = new Vector3f(rootNode.localTransform.getTranslation());
|
||||
|
||||
// Copy all rotations
|
||||
this.rotations = new HashMap<String, Quaternion>();
|
||||
rootNode.depthFirstTraversal(visitor -> {
|
||||
// Insert a copied quaternion so it isn't changed by reference
|
||||
rotations.put(visitor.getName(), new Quaternion(visitor.localTransform.getRotation()));
|
||||
});
|
||||
|
||||
this.positions = null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user