mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-20 09:01:20 -08:00
Allow multiple TrackerFrames with the same designation in PoseFrame, make TrackerFrame extend Tracker
This commit is contained in:
6 files changed
+139
-34
No files matched your search
@@ -203,7 +203,7 @@ public class AutoBone {
|
||||
public float getMaxHmdHeight(PoseFrame[] frames) {
|
||||
float maxHeight = 0f;
|
||||
for (PoseFrame frame : frames) {
|
||||
TrackerFrame hmd = frame.trackerFrames.get(TrackerBodyPosition.HMD);
|
||||
TrackerFrame hmd = frame.findTracker(TrackerBodyPosition.HMD);
|
||||
if (hmd != null && hmd.hasData(TrackerFrameData.POSITION) && hmd.position.y > maxHeight) {
|
||||
maxHeight = hmd.position.y;
|
||||
}
|
||||
@@ -414,7 +414,7 @@ public class AutoBone {
|
||||
float offset = 0f;
|
||||
int offsetCount = 0;
|
||||
|
||||
for (TrackerFrame trackerFrame : frame.trackerFrames.values()) {
|
||||
for (TrackerFrame trackerFrame : frame.trackerFrames) {
|
||||
if (!trackerFrame.hasData(TrackerFrameData.POSITION)) {
|
||||
continue;
|
||||
}
|
||||
@@ -434,12 +434,12 @@ public class AutoBone {
|
||||
float offset = 0f;
|
||||
int offsetCount = 0;
|
||||
|
||||
for (TrackerFrame trackerFrame1 : frame1.trackerFrames.values()) {
|
||||
for (TrackerFrame trackerFrame1 : frame1.trackerFrames) {
|
||||
if (!trackerFrame1.hasData(TrackerFrameData.POSITION)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
TrackerFrame trackerFrame2 = frame2.trackerFrames.get(trackerFrame1.designation);
|
||||
TrackerFrame trackerFrame2 = frame2.findTracker(trackerFrame1.designation);
|
||||
if (trackerFrame2 == null || !trackerFrame2.hasData(TrackerFrameData.POSITION)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ public class SimpleSkeleton {
|
||||
}
|
||||
|
||||
public void setPoseFromFrame(PoseFrame frame) {
|
||||
for (TrackerFrame trackerFrame : frame.trackerFrames.values()) {
|
||||
for (TrackerFrame trackerFrame : frame.trackerFrames) {
|
||||
// Set HMD position
|
||||
if (trackerFrame.designation == TrackerBodyPosition.HMD && trackerFrame.hasData(TrackerFrameData.POSITION)) {
|
||||
hmdNode.localTransform.setTranslation(trackerFrame.position);
|
||||
|
||||
@@ -1,27 +1,18 @@
|
||||
package dev.slimevr.vr.poserecorder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import io.eiren.util.collections.FastList;
|
||||
import io.eiren.vr.processor.TrackerBodyPosition;
|
||||
import io.eiren.vr.trackers.Tracker;
|
||||
import io.eiren.vr.trackers.TrackerUtils;
|
||||
|
||||
public final class PoseFrame {
|
||||
|
||||
public final HashMap<TrackerBodyPosition, TrackerFrame> trackerFrames;
|
||||
|
||||
public PoseFrame(HashMap<TrackerBodyPosition, TrackerFrame> trackerFrames) {
|
||||
this.trackerFrames = trackerFrames;
|
||||
}
|
||||
public final List<TrackerFrame> 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;
|
||||
this.trackerFrames = trackerFrames;
|
||||
}
|
||||
|
||||
public static PoseFrame fromTrackers(List<Tracker> trackers) {
|
||||
@@ -29,16 +20,26 @@ public final class PoseFrame {
|
||||
return null;
|
||||
}
|
||||
|
||||
HashMap<TrackerBodyPosition, TrackerFrame> trackerFrames = new HashMap<TrackerBodyPosition, TrackerFrame>(trackers.size());
|
||||
List<TrackerFrame> trackerFrames = new FastList<TrackerFrame>(trackers.size());
|
||||
|
||||
for (Tracker tracker : trackers) {
|
||||
TrackerFrame trackerFrame = TrackerFrame.fromTracker(tracker);
|
||||
|
||||
if (trackerFrame != null) {
|
||||
trackerFrames.put(trackerFrame.designation, trackerFrame);
|
||||
trackerFrames.add(trackerFrame);
|
||||
}
|
||||
}
|
||||
|
||||
return new PoseFrame(trackerFrames);
|
||||
}
|
||||
|
||||
//#region Easy Utility Access
|
||||
public TrackerFrame findTracker(TrackerBodyPosition designation) {
|
||||
return (TrackerFrame)TrackerUtils.findTrackerForBodyPosition(trackerFrames, designation);
|
||||
}
|
||||
|
||||
public TrackerFrame findTracker(TrackerBodyPosition designation, TrackerBodyPosition altDesignation) {
|
||||
return (TrackerFrame)TrackerUtils.findTrackerForBodyPosition(trackerFrames, designation, altDesignation);
|
||||
}
|
||||
//#endregion
|
||||
}
|
||||
@@ -8,10 +8,12 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.HashMap;
|
||||
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;
|
||||
|
||||
@@ -41,7 +43,7 @@ public final class PoseFrameIO {
|
||||
if (frame != null && frame.trackerFrames != null) {
|
||||
outputStream.writeInt(frame.trackerFrames.size());
|
||||
|
||||
for (TrackerFrame trackerFrame : frame.trackerFrames.values()) {
|
||||
for (TrackerFrame trackerFrame : frame.trackerFrames) {
|
||||
outputStream.writeInt(trackerFrame.getDataFlags());
|
||||
|
||||
if (trackerFrame.hasData(TrackerFrameData.DESIGNATION)) {
|
||||
@@ -104,13 +106,15 @@ public final class PoseFrameIO {
|
||||
try {
|
||||
int trackerFrameCount = inputStream.readInt();
|
||||
|
||||
HashMap<TrackerBodyPosition, TrackerFrame> trackerFrames = new HashMap<TrackerBodyPosition, TrackerFrame>(trackerFrameCount);
|
||||
List<TrackerFrame> trackerFrames = new FastList<TrackerFrame>(trackerFrameCount);
|
||||
for (int i = 0; i < trackerFrameCount; i++) {
|
||||
int dataFlags = inputStream.readInt();
|
||||
|
||||
String designationString = null;
|
||||
TrackerBodyPosition designation = null;
|
||||
if (TrackerFrameData.DESIGNATION.check(dataFlags)) {
|
||||
designation = TrackerBodyPosition.getByDesignation(inputStream.readUTF());
|
||||
designationString = inputStream.readUTF();
|
||||
designation = TrackerBodyPosition.getByDesignation(designationString);
|
||||
}
|
||||
|
||||
Quaternion rotation = null;
|
||||
@@ -130,9 +134,7 @@ public final class PoseFrameIO {
|
||||
position = new Vector3f(posX, posY, posZ);
|
||||
}
|
||||
|
||||
if (designation != null) {
|
||||
trackerFrames.put(designation, new TrackerFrame(designation, rotation, position));
|
||||
}
|
||||
trackerFrames.add(new TrackerFrame(designationString, designation, rotation, position));
|
||||
}
|
||||
|
||||
return new PoseFrame(trackerFrames);
|
||||
|
||||
@@ -5,16 +5,25 @@ import com.jme3.math.Vector3f;
|
||||
|
||||
import io.eiren.vr.processor.TrackerBodyPosition;
|
||||
import io.eiren.vr.trackers.Tracker;
|
||||
import io.eiren.vr.trackers.TrackerConfig;
|
||||
import io.eiren.vr.trackers.TrackerStatus;
|
||||
|
||||
public final class TrackerFrame {
|
||||
public final class TrackerFrame implements Tracker {
|
||||
|
||||
private int dataFlags = 0;
|
||||
|
||||
public final String name;
|
||||
public final TrackerBodyPosition designation;
|
||||
public final Quaternion rotation;
|
||||
public final Vector3f position;
|
||||
|
||||
public TrackerFrame(TrackerBodyPosition designation, Quaternion rotation, Vector3f position) {
|
||||
public TrackerFrame(String designationString, TrackerBodyPosition designation, Quaternion rotation, Vector3f position) {
|
||||
if (designationString != null) {
|
||||
this.name = "TrackerFrame:/" + designationString;
|
||||
} else {
|
||||
this.name = "TrackerFrame";
|
||||
}
|
||||
|
||||
this.designation = designation;
|
||||
if (designation != null) {
|
||||
dataFlags |= TrackerFrameData.DESIGNATION.flag;
|
||||
@@ -31,6 +40,10 @@ public final class TrackerFrame {
|
||||
}
|
||||
}
|
||||
|
||||
public TrackerFrame(TrackerBodyPosition designation, Quaternion rotation, Vector3f position) {
|
||||
this(designation == null ? null : designation.designation, designation, rotation, position);
|
||||
}
|
||||
|
||||
public TrackerFrame(TrackerBodyPosition designation, Quaternion rotation) {
|
||||
this(designation, rotation, null);
|
||||
}
|
||||
@@ -67,4 +80,93 @@ public final class TrackerFrame {
|
||||
public boolean hasData(TrackerFrameData flag) {
|
||||
return flag.check(dataFlags);
|
||||
}
|
||||
|
||||
//#region Tracker Interface Implementation
|
||||
@Override
|
||||
public boolean getRotation(Quaternion store) {
|
||||
if (hasData(TrackerFrameData.ROTATION)) {
|
||||
store.set(rotation);
|
||||
return true;
|
||||
}
|
||||
|
||||
store.set(0, 0, 0, 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getPosition(Vector3f store) {
|
||||
if (hasData(TrackerFrameData.POSITION)) {
|
||||
store.set(position);
|
||||
return true;
|
||||
}
|
||||
|
||||
store.set(0, 0, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackerStatus getStatus() {
|
||||
return TrackerStatus.OK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadConfig(TrackerConfig config) {
|
||||
throw new UnsupportedOperationException("TrackerFrame does not implement this method");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveConfig(TrackerConfig config) {
|
||||
throw new UnsupportedOperationException("TrackerFrame does not implement this method");
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getConfidenceLevel() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetFull(Quaternion reference) {
|
||||
throw new UnsupportedOperationException("TrackerFrame does not implement this method");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetYaw(Quaternion reference) {
|
||||
throw new UnsupportedOperationException("TrackerFrame does not implement this method");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
throw new UnsupportedOperationException("TrackerFrame does not implement this method");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackerBodyPosition getBodyPosition() {
|
||||
return designation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBodyPosition(TrackerBodyPosition position) {
|
||||
throw new UnsupportedOperationException("TrackerFrame does not implement this method");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean userEditable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasRotation() {
|
||||
return hasData(TrackerFrameData.ROTATION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPosition() {
|
||||
return hasData(TrackerFrameData.POSITION);
|
||||
}
|
||||
//#endregion
|
||||
}
|
||||
@@ -8,8 +8,8 @@ public class TrackerUtils {
|
||||
|
||||
private TrackerUtils() {
|
||||
}
|
||||
|
||||
public static Tracker findTrackerForBodyPosition(List<Tracker> allTrackers, TrackerBodyPosition position) {
|
||||
|
||||
public static Tracker findTrackerForBodyPosition(List<? extends Tracker> allTrackers, TrackerBodyPosition position) {
|
||||
for(int i = 0; i < allTrackers.size(); ++i) {
|
||||
Tracker t = allTrackers.get(i);
|
||||
if(t.getBodyPosition() == position)
|
||||
@@ -17,15 +17,15 @@ public class TrackerUtils {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Tracker findTrackerForBodyPosition(List<Tracker> allTrackers, TrackerBodyPosition position, TrackerBodyPosition altPosition) {
|
||||
|
||||
public static Tracker findTrackerForBodyPosition(List<? extends Tracker> allTrackers, TrackerBodyPosition position, TrackerBodyPosition altPosition) {
|
||||
Tracker t = findTrackerForBodyPosition(allTrackers, position);
|
||||
if(t != null)
|
||||
return t;
|
||||
return findTrackerForBodyPosition(allTrackers, altPosition);
|
||||
}
|
||||
|
||||
public static Tracker findTrackerForBodyPositionOrEmpty(List<Tracker> allTrackers, TrackerBodyPosition position, TrackerBodyPosition altPosition) {
|
||||
|
||||
public static Tracker findTrackerForBodyPositionOrEmpty(List<? extends Tracker> allTrackers, TrackerBodyPosition position, TrackerBodyPosition altPosition) {
|
||||
Tracker t = findTrackerForBodyPosition(allTrackers, position);
|
||||
if(t != null)
|
||||
return t;
|
||||
|
||||
Reference in new issue
Block a user