microsoft / OpenXR-Unity-MixedReality-Samples

Sample Unity projects to demo how to use OpenXR plugin in Unity for HoloLens 2 and Mixed Reality headsets
MIT License
250 stars 71 forks source link

How to use XRAnchorTransferBatch.ImportAsync(Stream) on Hololens 2 #149

Closed ChasingD closed 1 year ago

ChasingD commented 1 year ago

openxr version 1.8.0 I use XRAnchorTransferBatch to export anchors, but when I import anchors using XRAnchorTransferBatch.ImportAsync(Stream), null is returned.

Stream stream = new MemoryStream(anchorData); stream.Seek(0, SeekOrigin.Begin); var transferBatch = await XRAnchorTransferBatch.ImportAsync(stream);

anchorData is byte[] transfered. result: transferBatch is null

ChasingD commented 1 year ago

public static async Task ImportAsync(Stream inputStream) { AnchorTransferBatch anchorTransfer = new AnchorTransferBatch(); SerializationCompletionReason num = await anchorTransfer.ImportAsync(inputStream); if (num == SerializationCompletionReason.Succeeded) { return new XRAnchorTransferBatch(anchorTransfer); } return null; }

Result: SerializationCompletionReason is UnknownError

WikkidEdd commented 1 year ago

Presumably, you're transferring the anchor data over a network connection or something? Have you confirmed that the anchorData isn't being transformed somehow as part of the transfer process? i.e checking the size and doing a checksum on the byte array.

ChasingD commented 1 year ago

Presumably, you're transferring the anchor data over a network connection or something? Have you confirmed that the anchorData isn't being transformed somehow as part of the transfer process? i.e checking the size and doing a checksum on the byte array.

Hi WikkidEdd, thanks for your reply. I found the problem inspired by you. The problem is the anchor data is wrong during the export phase. So the data imported is wrong.

hemasree99s commented 1 year ago

trying using as below using (MemoryStream stream = new MemoryStream(rawAnchorDownloadedData)) { stream.Write(rawAnchorDownloadedData, 0, rawAnchorDownloadedData.Length); stream.Seek(0, SeekOrigin.Begin); currentAnchorTransferBatch = await XRAnchorTransferBatch.ImportAsync(stream); }

AMollis commented 1 year ago

@ChasingD is there still an issue here? From your last comment, sounds like you discovered problem with the exported data.

The problem is the anchor data is wrong during the export phase. So the data imported is wrong.

If there is still an obvious bug, please reply here. Also, in this case, can you provide a Unity project with an isolated reproduction of the bug? This will help expediate the investigation on our side.

If you are in need of API assistance, meaning there is no obvious API bug, please follow-up with our support team via https://aka.ms/mrsupport. In this case, you would select help with "HoloLens Devices" and "HoloLens App Development (HL 2)", concerning an "API" and "Spatial Anchors" issue. Our support team will then assist you with using this API.

image

Mirgiacomo commented 1 year ago

Hi @ChasingD , I'm working on something similar but I'm having problems with the export phase of the anchors (I want export anchors on a database) Can you provide me the piece of code/function that does the export? and the import?

Thanks