Skip to content

Commit

Permalink
Send any computed tracker via VMC for props (#719)
Browse files Browse the repository at this point in the history
Co-authored-by: Uriel <[email protected]>
  • Loading branch information
Erimelowo and ImUrX authored Jul 27, 2023
1 parent 0ad237a commit d89a4c2
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 34 deletions.
3 changes: 3 additions & 0 deletions server/core/src/main/java/dev/slimevr/VRServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ class VRServer @JvmOverloads constructor(
private fun trackerAdded(tracker: Tracker) {
humanPoseManager.trackerAdded(tracker)
updateSkeletonModel()
if (tracker.isComputed && tracker.name != "HMD") {
vMCHandler.addComputedTracker(tracker)
}
refreshTrackersDriftCompensationEnabled()
}

Expand Down
66 changes: 40 additions & 26 deletions server/core/src/main/java/dev/slimevr/osc/VMCHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class VMCHandler implements OSCHandler {
private final VMCConfig config;
private final VRServer server;
private final HumanPoseManager humanPoseManager;
private final List<Tracker> computedTrackers;
private final List<Tracker> computedTrackers = new FastList<>();
private final FastList<Object> oscArgs = new FastList<>();
private final long startTime;
private final Map<String, Tracker> byTrackerNameTracker = new HashMap<>();
Expand All @@ -65,7 +65,6 @@ public VMCHandler(
this.server = server;
this.humanPoseManager = humanPoseManager;
this.config = oscConfig;
this.computedTrackers = computedTrackers;

startTime = System.currentTimeMillis();

Expand Down Expand Up @@ -453,31 +452,37 @@ && isRightArmUnityBone(bone))
}
}

for (Tracker shareableTracker : computedTrackers) {
oscArgs.clear();
oscArgs.add(String.valueOf(shareableTracker.getId()));
addTransformToArgs(
shareableTracker.getPosition(),
shareableTracker.getRotation()
);
String address;
TrackerPosition role = shareableTracker.getTrackerPosition();
if (role == TrackerPosition.HEAD) {
address = "/VMC/Ext/Hmd/Pos";
} else if (
role == TrackerPosition.LEFT_HAND || role == TrackerPosition.RIGHT_HAND
) {
address = "/VMC/Ext/Con/Pos";
} else {
address = "/VMC/Ext/Tra/Pos";
}
oscBundle
.addPacket(
new OSCMessage(
address,
oscArgs.clone()
)
for (Tracker tracker : computedTrackers) {
if (!tracker.getStatus().getReset()) {
oscArgs.clear();

String name = tracker.getName();
oscArgs.add(name);

addTransformToArgs(
tracker.getPosition(),
tracker.getRotation()
);

String address;
TrackerPosition role = tracker.getTrackerPosition();
if (role == TrackerPosition.HEAD) {
address = "/VMC/Ext/Hmd/Pos";
} else if (
role == TrackerPosition.LEFT_HAND || role == TrackerPosition.RIGHT_HAND
) {
address = "/VMC/Ext/Con/Pos";
} else {
address = "/VMC/Ext/Tra/Pos";
}
oscBundle
.addPacket(
new OSCMessage(
address,
oscArgs.clone()
)
);
}
}

// Send OSC packets as bundle
Expand Down Expand Up @@ -508,6 +513,15 @@ public void alignVMCTracking(Quaternion reference) {
yawOffset = reference.project(Vector3.Companion.getPOS_Y()).unit();
}

/**
* Add a computed tracker to the list of trackers to send.
*
* @param computedTracker the computed tracker
*/
public void addComputedTracker(Tracker computedTracker) {
computedTrackers.add(computedTracker);
}

private void addTransformToArgs(Vector3 pos, Quaternion rot) {
oscArgs.add(pos.getX());
oscArgs.add(pos.getY());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import dev.slimevr.tracking.trackers.Tracker;
import dev.slimevr.tracking.trackers.TrackerPosition;
import dev.slimevr.tracking.trackers.TrackerRole;
import dev.slimevr.tracking.trackers.TrackerStatus;
import dev.slimevr.util.ann.VRServerThread;
import io.eiren.util.ann.ThreadSafe;
import io.eiren.util.collections.FastList;
Expand Down Expand Up @@ -314,6 +315,8 @@ private void initializeComputedHumanPoseTracker() {
true
)
);

connectComputedHumanPoseTrackers();
}

public void loadFromConfig(ConfigManager configManager) {
Expand All @@ -325,6 +328,12 @@ public void updateSkeletonModelFromServer() {
skeleton.setTrackersFromList(server.getAllTrackers());
}

private void connectComputedHumanPoseTrackers() {
for (Tracker t : computedTrackers) {
t.setStatus(TrackerStatus.OK);
}
}

// #endregion
// #region public methods
// #region skeleton methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ protected void trackerAddedReceived(TrackerAdded trackerAdded) {
remoteTrackersBySerial.put(tracker.getName(), tracker);
}
synchronized (remoteTrackersByTrackerId) {
remoteTrackersByTrackerId.put(tracker.getId(), tracker);
remoteTrackersByTrackerId.put(tracker.getTrackerNum(), tracker);
}
if (trackerAdded.getTrackerRole() == TrackerRole.HMD.getId()) {
hmdTracker = tracker;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected Tracker createNewTracker(ProtobufMessages.TrackerAdded trackerAdded) {
.createDevice(
trackerAdded.getTrackerName(),
trackerAdded.getTrackerSerial(),
"OpenVR"
"OpenVR" // TODO : We need the manufacturer
);

String displayName;
Expand All @@ -105,13 +105,11 @@ protected Tracker createNewTracker(ProtobufMessages.TrackerAdded trackerAdded) {

Tracker tracker = new Tracker(
device,
// FIXME use SteamVR tracker's id for SlimeVR tracker's trackerNum,
// and use VRServer's unique id for SlimeVR tracker' id
trackerAdded.getTrackerId(),
trackerAdded.getTrackerName(),
VRServer.getNextLocalTrackerId(),
trackerAdded.getTrackerSerial(),
displayName,
null,
null,
trackerAdded.getTrackerId(),
true,
true,
false,
Expand Down Expand Up @@ -352,7 +350,7 @@ protected void writeBatteryUpdate(Tracker localTracker) {
}
}

Battery.Builder builder = Battery.newBuilder().setTrackerId(localTracker.getId());
Battery.Builder builder = Battery.newBuilder().setTrackerId(localTracker.getTrackerNum());

builder.setBatteryLevel(trackerLevel);
builder.setIsCharging(isCharging);
Expand Down

0 comments on commit d89a4c2

Please sign in to comment.