Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.
Options

share SpatialAnchor in UWP app

Hi everyone,

I'm trying to share an Anchor using SpatialAnchorTransferManager.
I export the anchor with this code and it seems to go well:
private static async void ExportAnchors(List anchors,string fileName)
{
var folder = ApplicationData.Current.LocalFolder;
using (Stream stream = OpenFileForWriting(folder, fileName.Substring(0, fileName.LastIndexOf(".obj")) + ".sanchors").Result)
{
using (StreamWriter writer = new StreamWriter(stream))
{
foreach (ManagedSpatialAnchor anchor in anchors)
{
MemoryStream mstream = new MemoryStream(1 * 1024);
Dictionary<string, SpatialAnchor> map = new Dictionary<string, SpatialAnchor>(1)
{
{anchor.index.ToString(), anchor.anchor}
};
bool success = await SpatialAnchorTransferManager.TryExportAnchorsAsync(map, mstream.AsOutputStream());
if (success)
{
byte[] anchorDataBytes = mstream.ToArray();
writer.WriteLine(string.Format("sa {0}", BitConverter.ToString(anchorDataBytes).Replace("-", "")));
}
}
}
}
}

in import anchorsMap is null:
private async void LoadOldAnchors()
{
var status = await SpatialAnchorTransferManager.RequestAccessAsync();
m_oldanchors = new List();
var files = await ApplicationData.Current.LocalFolder.GetFilesAsync();
var filesList =files.ToList();
foreach (var file in files)
{
if (file.Name.Contains(".sanchors"))
{
using (Stream stream = await file.OpenStreamForReadAsync())
{
using (StreamReader reader = new StreamReader(stream))
{
SpatialAnchor spatialAnchor;
while(!reader.EndOfStream)
{
string line = reader.ReadLine();
switch(line.Substring(0,2))
{
case "sa":
int start = 3;
int length = (line.Length - start) / 2;
byte[] anchorDataBytes = new byte[length];
for (int i=0; i<length;i++)
{
anchorDataBytes[i] = (byte)(GetHexVal(line[2 * i + 1+start]) + (GetHexVal(line[2 * i+start]) << 4));
}
MemoryStream memoryStream = new MemoryStream(anchorDataBytes);
IInputStream inputStream = memoryStream.AsInputStream();
var importAnchorOperation = SpatialAnchorTransferManager.TryImportAnchorsAsync(inputStream);
importAnchorOperation.Completed = (asyncInfo, asyncStatus) =>
{
switch (asyncStatus)
{
case AsyncStatus.Completed:
var anchorsMap = asyncInfo.GetResults();
spatialAnchor = anchorsMap.Values.ToList()[0];
m_oldanchors.Add(spatialAnchor);
break;
case AsyncStatus.Canceled:
break;
case AsyncStatus.Error:
break;
case AsyncStatus.Started:
break;
}
};
break;
}
}
}
}
break;
}
}
await Task.Run(() => ClearStorageFolder());
}

do you know how to solve it?
thanks

Sign In or Register to comment.