Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't create new skeletons #761

Merged
merged 4 commits into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
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 @@ -50,7 +49,14 @@ private HumanPoseManager() {
*/
public HumanPoseManager(VRServer server) {
this();
skeleton = new HumanSkeleton(this, server);
this.server = server;
// This computes all node offsets, so the defaults don't need to be
// explicitly loaded into the skeleton (no need for
// `updateNodeOffsetsInSkeleton()`)
loadFromConfig(server.configManager);
for (Consumer<HumanSkeleton> sc : onSkeletonUpdated)
sc.accept(skeleton);
}

/**
Expand Down Expand Up @@ -316,43 +322,7 @@ public void loadFromConfig(ConfigManager configManager) {

@VRServerThread
public void updateSkeletonModelFromServer() {
disconnectComputedHumanPoseTrackers();

// Make a new skeleton and store the old state
HumanSkeleton oldSkeleton = skeleton;
skeleton = new HumanSkeleton(this, server);

// Transfer the state of the old skeleton to the new one
if (oldSkeleton != null) {
skeleton.setPauseTracking(oldSkeleton.getPauseTracking());

// If paused, copy the pose to the new skeleton so it doesn't reset
// to t-pose each time
if (oldSkeleton.getPauseTracking()) {
TransformNode[] oldNodes = oldSkeleton.getAllNodes();
TransformNode[] newNodes = skeleton.getAllNodes();

for (int i = 0; i < newNodes.length; i++) {
newNodes[i]
.getLocalTransform()
.setRotation(oldNodes[i].getLocalTransform().getRotation());
}
}
}

// This recomputes all node offsets, so the defaults don't need to be
// explicitly loaded into the skeleton (no need for
// `updateNodeOffsetsInSkeleton()`)
loadFromConfig(server.configManager);
for (Consumer<HumanSkeleton> sc : onSkeletonUpdated)
sc.accept(skeleton);
}

@VRServerThread
private void disconnectComputedHumanPoseTrackers() {
for (Tracker t : computedTrackers) {
t.setStatus(TrackerStatus.DISCONNECTED);
}
skeleton.setTrackersFromList(server.getAllTrackers());
}

// #endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ protected void resetBones() {


// #region Set trackers inputs
protected void setTrackersFromList(List<Tracker> trackers) {
public void setTrackersFromList(List<Tracker> trackers) {
headTracker = TrackerUtils
.getTrackerForSkeleton(
trackers,
Expand Down