microsoft / MixedReality-WorldLockingTools-Unity

Unity tools to provide a stable coordinate system anchored to the physical world.
https://microsoft.github.io/MixedReality-WorldLockingTools-Unity/README.html
MIT License
188 stars 45 forks source link

Question: proper use of AdjusterFixed and AdjusterMoving components #281

Closed genereddick closed 2 years ago

genereddick commented 2 years ago

I'm trying to understand the proper use for the AdjusterFixed and AdjusterMoving (or derived versions) components. I understand that they handle Refit operations and allow you to choose what to do in that event with the default method, meant to be overridden, automatically handling pose adjustments (HandleAdjustLocation).

 protected virtual void HandleAdjustLocation(Pose adjustment)
 {
       ...
        Pose pose = gameObject.transform.GetGlobalPose();
        pose = adjustment.Multiply(pose);
        gameObject.transform.SetGlobalPose(pose);
}

Questions:

  1. Do you only need to use Adjusters if you want to handle a refit in some special way?
  2. If Adjusters update poses when responding to the HandleAdjustLocation how do assets that don't have Adjusters on them deal with this?
  3. Why wouldn't all assets (assuming they are themselves not pinned) need Adjusters?
fast-slow-still commented 2 years ago

It's important to note that the SpacePins also handle refit operations. If you are using SpacePins, you don't need adjusters, as rather than adjusting objects individually on refit events, the entire pinned space is adjusted. You might still want adjusters, for example in order to just be notified that a refit event has occurred.

Also note that the Adjuster helpers are simply convenience components for the AttachmentPoint, which is the notification pattern for WLT notifying the client application of refit events. Adjuster components can be used as is, or as examples of handling the notifications (along with registration etc), or bypassed entirely.

Do you only need to use Adjusters if you want to handle a refit in some special way?

Yes, that's correct.

If Adjusters update poses when responding to the HandleAdjustLocation how do assets that don't have Adjusters on them deal with this?

Assets without Adjusters don't deal with refit events. Dealing with refit events may or may not make sense for any given asset. More below.

Why wouldn't all assets (assuming they are themselves not pinned) need Adjusters?

An object needs an Adjuster (or equivalent) if it needs to deal with refit events.

Assets in a SpacePinned space don't need to deal with refit events, as the entire space is adjusted. Assets that are body-locked don't need to deal with refit events. Assets whose lifespan is short relative to the frequency of refit events usually don't need to deal with refit events.

Additionally, for collections of objects, you need to handle the refit event for the collection as a single object, e.g. applying any adjustment at the root, or be prepared for objects within the collection moving relative to each other. Which is better depends on the application and the nature of the collection of objects.

All of this suggests that the reaction to refit operations ultimately needs to be left to the application, as the ideal reaction will be different from application to application, and even for different objects within a single application.

Refit events are the system trying to compensate for something having gone wrong, generally loss of tracking or large loop closure error. See the discussion in issue #280 on mitigating those errors, and so the need for refit event handling, with techniques like pre-scanning.

genereddick commented 2 years ago

Re: Assets in a SpacePinned space don't need to deal with refit events

Does this apply to assets that are children of pinned objects, or is having a single space pin in a scene sufficient to make the entire scene a SpacePinned space?

For example, In the WorldLockingPhysicsSample scene from WorldLocking.Examples, the Beams, Pillars, Spheres and Darts are not instantiated under a SpacePinned object and the Beams, Pillars and Darts have Adjuster components attached to them. Is this because they are not children of a space pinned object?

Separately, the Spheres have a ToggleWorldAnchor component which seem to be updated every frame (but only in Legacy WSA) -- I'm not sure exactly how this fits into the pattern with the others? Also, what is the purpose of the unlocked, vs, hybrid vs world locked setting here?

fast-slow-still commented 2 years ago

In the WLT realm, you don't pin objects, you pin coordinate spaces.

Maybe a simple analogy might help clarify this. Imagine you have a 10 meter square physical room. Now imagine you have a roughly 10 meter square slightly stretchy rug. It's only roughly 10 meter square because it can stretch, and it can bunch up, so it's dimensions can't be measured exactly.

The rug doubles as a schematic, with drawings of where the furniture should be placed.

Now you want to lay the rug out matching the room. You could take a single alignment point, say the center of the rug, and match it to the center of the floor. That would work, but it won't be a very good fit. By the time you get to the edges of the rug, you'll have accumulated error from the rug bunching and stretching, and of course any slight rotation error at the center will be amplified to a significant error at the edges.

So a better plan might be to pin the rug down at the four corners of the room. It will obviously be correctly aligned at the corners, but the stretchiness of the rug will tend to make it line up pretty well in the middle too. If the center isn't well enough aligned, then you might add another pin in the center as well.

Now the foreman comes in and says, "Oops, when we put this room together, we accidentally made it a trapezoid instead of a square, we'll fix that now." She tells you the corrections they're making, and it's no problem for you, you just apply those corrections to your pin locations. You don't need to alter the diagrams on your schematic rug, when your rug is shifted, all of the diagrams get shifted along with it.

Notice that if you weren't pinning the whole schematic rug, if you had just laid down diagrams where the furniture should go, then you would need to apply corrections to each of the individual diagrams.

Schematic rug == Pinned frozen space Diagrams on rug == holograms Rug stretching and bunching == deformations of space due to tracker error Pinning the rug down == SpacePins Foreman adjusting room == Refit event Applying adjustment to pinned rug corners == SpacePins handling refit events Applying adjustments to individual diagrams (no rug) == Adjusters handling refit events

One last note, the Physics sample predates the SpacePins. SpacePins are added to it mostly as a convenience for testing. Use the SpacePin specific samples as a pattern for proper use of SpacePins (e.g. SpacePin.unity, RayPins.unity, AlignSubscene, QRSpacePins, PinTestSofa, etc.).

genereddick commented 2 years ago

@fast-slow-still OK, that's clear, Thanks!