Skip to content
This repository was archived by the owner on Nov 16, 2024. It is now read-only.

Commit 991a5c2

Browse files
Raise creation point of underlying anchors (#244)
* Move anchor creation to camera position from legacy position 1 meter down. Fix compatibility bug with ASA 2.11 Read (Search unaffected). Bump version to v1.5.7. * Add option to zero out pitch and roll from correction computed by FrozenWorldEngine.
1 parent 8ae45a6 commit 991a5c2

16 files changed

Lines changed: 77 additions & 19 deletions

File tree

Assets/WorldLocking.ASA/Scripts/PublisherASA.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,8 +1231,8 @@ private async Task<LocalPeg> InternalCreateLocalPeg(string id, Pose lockedPose)
12311231
+ $" pa={WorldLockingManager.GetInstance().AnchorManager.AnchorFromSpongy.Inverse().Multiply(frozenPose).position.ToString("F3")}"
12321232
);
12331233

1234-
#if WLT_ASA_SESSION_ORIGIN_WORKAROUND
1235-
// mafinc - workaround for bug in ASA NativeAnchor.
1234+
#if WLT_ASA_V2_10_2_OR_OLDER && WLT_ASA_SESSION_ORIGIN_WORKAROUND
1235+
// mafinc - workaround for bug in ASA NativeAnchor. Not needed (and breaks things) for ASA v2.11 and later.
12361236
peg.anchorHanger.transform.SetLocalPose(Pose.identity);
12371237
#endif // WLT_ASA_SESSION_ORIGIN_WORKAROUND
12381238

Assets/WorldLocking.ASA/Scripts/SpacePinBinder.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ public async Task<bool> Search()
327327
SpacePinASA spacePin = spacePins[idx];
328328

329329
Pose lockedPose = wltMgr.LockedFromFrozen.Multiply(pegAndProps.localPeg.GlobalPose);
330+
SimpleConsole.AddLine(ConsoleLow, $"Srch: {lockedPose.ToString("F3")}");
330331
spacePin.SetLockedPose(lockedPose);
331332
spacePin.SetLocalPeg(pegAndProps.localPeg);
332333
}

Assets/WorldLocking.Core/Editor/WorldLockingContextEditor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ public override void OnInspectorGUI()
7878
{
7979
AddProperty(mgrPath, "applyAdjustment");
8080

81+
AddProperty(mgrPath, "NoPitchAndRoll");
82+
8183
AddProperty(mgrPath, "AdjustmentFrame");
8284

8385
AddProperty(mgrPath, "CameraParent");

Assets/WorldLocking.Core/Scripts/AnchorManager.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,8 @@ public virtual bool Update()
234234
//
235235
Pose spongyHead = headTracker.GetHeadPose();
236236

237-
// place new anchors 1m below head
237+
// place new anchors at head
238238
Pose newSpongyAnchorPose = spongyHead;
239-
newSpongyAnchorPose.position.y -= 1;
240239
newSpongyAnchorPose.rotation = Quaternion.identity;
241240

242241
var activeAnchors = new List<AnchorPose>();

Assets/WorldLocking.Core/Scripts/LinkageSettings.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ public bool UseExisting
4141
[Tooltip("Apply world locking adjustment to the AdjustmentFrame.")]
4242
private bool applyAdjustment;
4343

44+
/// <summary>
45+
/// Zero out pitch and roll from the FrozenWorldEngine correction.
46+
/// </summary>
47+
[Tooltip("Zero out pitch and roll from the FrozenWorldEngine correction.")]
48+
public bool NoPitchAndRoll;
49+
4450
/// <summary>
4551
/// Apply world locking adjustment to the AdjustmentFrame.
4652
/// </summary>
@@ -72,6 +78,7 @@ public bool UseExisting
7278
public void InitToDefaults()
7379
{
7480
UseExisting = false;
81+
NoPitchAndRoll = false;
7582
ApplyAdjustment = true;
7683
AdjustmentFrame = null;
7784
CameraParent = null;

Assets/WorldLocking.Core/Scripts/WorldLockingManager.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class WorldLockingManager
3535
/// allowing quick visual verification of the version of World Locking Tools for Unity currently installed.
3636
/// It has no effect in code, but serves only as a label.
3737
/// </summary>
38-
public static string Version => "1.5.5";
38+
public static string Version => "1.5.7";
3939

4040
/// <summary>
4141
/// The configuration settings may only be set as a block.
@@ -151,6 +151,13 @@ public DiagnosticsSettings DiagnosticsSettings
151151
/// </remarks>
152152
public bool ApplyAdjustment => shared.linkageSettings.ApplyAdjustment;
153153

154+
/// <summary>
155+
/// Zero out pitch and roll from FrozenWorldEngine's computed correction.
156+
/// </summary>
157+
/// <remarks>
158+
/// This does not affect pitch and roll from the AlignmentManager (SpacePins).
159+
/// </remarks>
160+
public bool NoPitchAndRoll => shared.linkageSettings.NoPitchAndRoll;
154161

155162
/// <summary>
156163
/// Direct interface to the plugin. It is not generally necessary or desired to
@@ -683,6 +690,10 @@ private void Update()
683690
if (Enabled)
684691
{
685692
Pose playspaceFromLocked = Plugin.GetAlignment();
693+
if (NoPitchAndRoll)
694+
{
695+
playspaceFromLocked.rotation = Quaternion.Euler(0f, playspaceFromLocked.rotation.eulerAngles.y, 0f); // Zero out X and Z rotation from frozen world engine
696+
}
686697
LockedFromPlayspace = playspaceFromLocked.Inverse();
687698

688699
SpongyFromCamera = Plugin.GetSpongyHead();

Assets/WorldLocking.Tools/Scripts/AnchorGraphVisual.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@ public class AnchorGraphVisual : MonoBehaviour
3939
[SerializeField]
4040
private Material connectingLine = null;
4141

42+
/// <summary>
43+
/// Vertical distance to offset from actual anchors, to avoid visuals at eye level.
44+
/// </summary>
45+
/// <remarks>
46+
/// Set this to zero to display visuals at actual anchor locations.
47+
/// </remarks>
48+
public float VerticalDisplacement { get { return verticalDisplacement; } set { verticalDisplacement = value; } }
49+
50+
/// <summary>
51+
/// Vertical distance to offset from actual anchors, to avoid visuals at eye level.
52+
/// </summary>
53+
/// <remarks>
54+
/// Set this to zero to display visuals at actual anchor locations.
55+
/// </remarks>
56+
[Tooltip("Vertical distance to offset from actual anchors, to avoid visuals at eye level.")]
57+
[SerializeField]
58+
private float verticalDisplacement = -1.0f;
4259
#endregion Public properties
4360

4461
#region Internal properties
@@ -166,7 +183,7 @@ private void UpdateSpongy()
166183
var spongyCurrent = anchorManager.SpongyAnchors;
167184
spongyCurrent.Sort((x, y) => x.anchorId.CompareTo(y.anchorId));
168185

169-
SpongyVisualCreator spongyCreator = new SpongyVisualCreator(Prefab_SpongyAnchorViz, spongyWorldViz);
186+
SpongyVisualCreator spongyCreator = new SpongyVisualCreator(Prefab_SpongyAnchorViz, spongyWorldViz, verticalDisplacement);
170187
ResourceMirror.Sync(
171188
spongyCurrent,
172189
spongyResources,
@@ -220,6 +237,8 @@ private void UpdateFrozen()
220237

221238
/// The "frozen" coordinates here are ignoring the rest of the transform up the camera tree.
222239
Pose globalFromLocked = manager.ApplyAdjustment ? manager.FrozenFromLocked : manager.SpongyFromLocked;
240+
/// Apply the vertical displacement through the globalFromLocked transform.
241+
globalFromLocked.position = new Vector3(globalFromLocked.position.x, globalFromLocked.position.y + verticalDisplacement, globalFromLocked.position.z);
223242

224243
var frozenCreator = new FrozenAnchorVisualCreator(Prefab_FrozenAnchorViz, frozenFragmentVizs, globalFromLocked);
225244
ResourceMirror.Sync(
@@ -443,17 +462,19 @@ private class SpongyVisualCreator
443462
{
444463
private readonly SpongyAnchorVisual Prefab_SpongyAnchorVisual;
445464
private readonly FrameVisual spongyWorldVisual;
465+
private readonly float verticalDisplacement;
446466

447467
/// <summary>
448468
/// Constructor takes the prefab to construct the visual out of, and a FrameVisual
449469
/// to creat the visual attached to.
450470
/// </summary>
451471
/// <param name="prefab">Prefab to create the visual out of.</param>
452472
/// <param name="spongyWorldVisual">Parent of created visuals.</param>
453-
public SpongyVisualCreator(SpongyAnchorVisual prefab, FrameVisual spongyWorldVisual)
473+
public SpongyVisualCreator(SpongyAnchorVisual prefab, FrameVisual spongyWorldVisual, float verticalDisplacement)
454474
{
455475
Prefab_SpongyAnchorVisual = prefab;
456476
this.spongyWorldVisual = spongyWorldVisual;
477+
this.verticalDisplacement = verticalDisplacement;
457478
}
458479

459480
/// <summary>
@@ -466,7 +487,8 @@ public bool CreateSpongyVisual(AnchorManager.SpongyAnchorWithId source, out IdPa
466487
{
467488
var spongyAnchorVisual = Prefab_SpongyAnchorVisual.Instantiate(
468489
spongyWorldVisual,
469-
source.spongyAnchor);
490+
source.spongyAnchor,
491+
verticalDisplacement);
470492

471493
resource = new IdPair<AnchorId, SpongyAnchorVisual>()
472494
{

Assets/WorldLocking.Tools/Scripts/SpongyAnchorVisual.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,18 @@ public class SpongyAnchorVisual : MonoBehaviour
4343

4444
private Color color;
4545

46+
/// <summary>
47+
/// Set in AnchorGraphVisual.
48+
/// </summary>
49+
private float verticalDisplacement = 0;
50+
4651
/// <summary>
4752
/// Create a visualizer for a spongy anchor.
4853
/// </summary>
4954
/// <param name="parent">Coordinate space to create the visualizer in</param>
5055
/// <param name="spongyAnchor">The spongyAnchor component assigned to some other object that this object is supposed to sync with</param>
5156
/// <returns></returns>
52-
public SpongyAnchorVisual Instantiate(FrameVisual parent, SpongyAnchor spongyAnchor)
57+
public SpongyAnchorVisual Instantiate(FrameVisual parent, SpongyAnchor spongyAnchor, float verticalDisplacement)
5358
{
5459
var res = Instantiate(this, parent.transform);
5560
res.name = spongyAnchor.name;
@@ -59,6 +64,7 @@ public SpongyAnchorVisual Instantiate(FrameVisual parent, SpongyAnchor spongyAnc
5964
}
6065
res.spongyAnchor = spongyAnchor;
6166
res.color = Color.gray;
67+
res.verticalDisplacement = verticalDisplacement;
6268
return res;
6369
}
6470

@@ -74,7 +80,9 @@ private void Update()
7480
// The SpongyFrame is adjusted by FrozeWorld every frame. This means that giving a transform M relative to the SpongyFrame,
7581
// as done here, will put the object _relative to the camera_ in the same place as setting M as the world transform
7682
// if SpongyFrame wasn't there, i.e. Unity World Space.
77-
transform.SetLocalPose(spongyAnchor.SpongyPose);
83+
Pose localPose = spongyAnchor.SpongyPose;
84+
localPose.position = new Vector3(localPose.position.x, localPose.position.y + verticalDisplacement, localPose.position.z);
85+
transform.SetLocalPose(localPose);
7886

7987
if (!spongyAnchor.IsLocated)
8088
color = Color.gray;

UPM/asa_files/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
[See release notes](https://github.com/microsoft/MixedReality-WorldLockingTools-Unity/releases)
44

5+
## 1.5.7 - Increased anchor stabilization.
6+
57
## 1.5.6 - Update to ASA v2.11.0.
68

79
## 1.5.4 - Fix timing issue with ASA anchors sometimes not created in time.

UPM/asa_files/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.microsoft.mixedreality.wlt.asa",
33
"displayName": "WLT-ASA",
4-
"version": "1.5.6",
4+
"version": "1.5.7",
55
"unity": "2020.3",
66
"msftFeatureCategory": "World Locking Tools",
77
"description": "World Locking Tools for Unity (WLT) + Azure Spatial Anchors (ASA)\n\nThis optional add-on to WLT leverages ASA to persist coordinate spaces across sessions and share them across devices.\nCross platform support includes HoloLens, Android, and iOS.",
@@ -35,7 +35,7 @@
3535
},
3636
"dependencies": {
3737
"com.microsoft.azure.spatial-anchors-sdk.core": "2.11.0",
38-
"com.microsoft.mixedreality.worldlockingtools": "1.5.6"
38+
"com.microsoft.mixedreality.worldlockingtools": "1.5.7"
3939
},
4040
"files": [
4141
"WorldLocking.ASA",

0 commit comments

Comments
 (0)