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

MRTK Profile Spatial Awareness/Mapping Layer Not Obtained #183

Closed Waffle1434 closed 3 years ago

Waffle1434 commented 3 years ago

When running the OMPTest sample scene, console log spammed with this error:

A game object can only be in one layer. The layer needs to be in the range [0...31]
UnityEngine.StackTraceUtility:ExtractStackTrace ()
Microsoft.MixedReality.WorldLocking.Tools.FrozenSpatialMapping:SurfaceChangedHandler (UnityEngine.XR.WSA.SurfaceId,UnityEngine.XR.WSA.SurfaceChange,UnityEngine.Bounds,System.DateTime) (at Library/PackageCache/com.microsoft.mixedreality.worldlockingtools@8b8274cd779c-1626820768821/WorldLocking.Tools/Scripts/FrozenSpatialMapping.cs:415)
UnityEngine.XR.WSA.SurfaceObserver:Update (UnityEngine.XR.WSA.SurfaceObserver/SurfaceChangedDelegate)
Microsoft.MixedReality.WorldLocking.Tools.FrozenSpatialMapping:UpdateObserver () (at Library/PackageCache/com.microsoft.mixedreality.worldlockingtools@8b8274cd779c-1626820768821/WorldLocking.Tools/Scripts/FrozenSpatialMapping.cs:297)
Microsoft.MixedReality.WorldLocking.Tools.FrozenSpatialMapping:Update () (at Library/PackageCache/com.microsoft.mixedreality.worldlockingtools@8b8274cd779c-1626820768821/WorldLocking.Tools/Scripts/FrozenSpatialMapping.cs:242)

My project's layers: image

When setting a breakpoint, spatialMappingLayer is -1, as its searching for the layer "SpatialMapping", instead of the layer used by MRTK ("Spatial Awareness").

Instead of:

spatialMappingLayer = LayerMask.NameToLayer("SpatialMapping");

Maybe something like this should work:

spatialMappingLayer = 0;
var spatialMappingConfig = (MixedRealitySpatialAwarenessSystemProfile)CoreServices.SpatialAwarenessSystem.ConfigurationProfile;
if (spatialMappingConfig != null) {
    foreach (var config in spatialMappingConfig.ObserverConfigurations) {
        var observerProfile = (MixedRealitySpatialAwarenessMeshObserverProfile)config.ObserverProfile;
        if (observerProfile != null) spatialMappingLayer |= (1 << observerProfile.MeshPhysicsLayer);
    }
}

I couldn't apply this solution as it would require changing the assembly definition dependencies. I suppose as an alternative to using MRTK, the layer could be supplied via inspector

public LayerMask spatialMappingLayer;
fast-slow-still commented 3 years ago

Hi "Waffle", sorry for the delay, but I've been away.

The FrozenSpatialMapping component in the OMPTest scene is obsolete. I will put in a task to remove the OMPTest scene entirely, as it is a specific calibration scene useful only to myself, and not really suitable for the general public.

If you are looking for a general sample scene to evaluate WLT, I would recommend the WorldLockedPhysics scene. It has a little of everything, and some (crude) UI to experiment with.

If you are looking for something more specific, let me know what your interests and constraints are. I would be happy to try to help you get comfortable with WLT as efficiently as possible. Also, please be specific about which platform(s) you will be deploying to.

Thanks for your interest!