Hololens2 Correct Usage of SpatialAnchors - hololens

I am trying to implement an Hololens 2 App using SpatialAnchors but it seems that I am not quite understanding the concept right. I am able to create, save and restore SpatialAnchors of the Windows.Perception.Spatial namespace, but whenever I restore them they are placed relative to the start position of the headset.
I use this snippet to create an anchor:
SpatialAnchor thisAnchor = SpatialAnchor.TryCreateRelativeTo(coord);
And this to get the relative SpatialCoordinateSystem (from this post)
public static bool UseSGIPSceneCoordinateSystem(out SpatialCoordinateSystem sGIPSceneCoordinateSystem)
{
// gain access to the scene object
SceneObserverAccessStatus accessStatus = Task.Run(RequestAccess).GetAwaiter().GetResult();
if (accessStatus == SceneObserverAccessStatus.Allowed)
{
Scene scene = Task.Run(GetSceneAsync).GetAwaiter().GetResult();
sGIPSceneCoordinateSystem = SpatialGraphInteropPreview.CreateCoordinateSystemForNode(scene.OriginSpatialGraphNodeId);
return true;
}
else
{
sGIPSceneCoordinateSystem = null;
return false;
}
}
I use this method to restore the SpatialAnchor I need:
public bool GetAnchor(string id, out SpatialAnchor anchor)
{
[...]
_anchors = _anchorStore.GetAllSavedAnchors();
foreach (var kvp in _anchors)
{
if(kvp.Key == id)
{
anchor = kvp.Value;
return true;
}
}
anchor = null;
return false;
}
And this to process the restored Anchor and get a place in the scene for it:
public void SomeOtherMethod(SpatialAnchor anchor)
{
SpatialCoordinateSystem showcaseCoordinateSystem = anchor.CoordinateSystem;
//get the reference SpatialCoordinateSystem
if (!UseSGIPSceneCoordinateSystem(out SpatialCoordinateSystem referenceCoordinateSystem))
return;
_anchorMatrix = showcaseCoordinateSystem.TryGetTransformTo(referenceCoordinateSystem);
System.Numerics.Matrix4x4 _notNullMatrix = _anchorMatrix.Value;
Matrix4x4 unityAnchorMatrix = _notNullMatrix.ToUnity();
anchorGameObject.transform.FromMatrix(unityAnchorMatrix);
}
I think that I am using the wrong SpatialCoordinateSystem but canĀ“t find information on how to get a SpatialCoordinateSystem which the HoloLens2 generates for the physical spatial surrounding of the user that is persistent.
I am using:
Unity 2020.3.13f1
OpenXR Plugin 1.3.1
MRTK 2.7.3
MRTK-OpenXR 1.2.1
MRTK SceneUnderstanding 0.6.0
I am also confused of the amount of different SpatialAnchor-Systems, reference coordinatesystems and the documentation. Every post I find about SpatialAnchors seems to use a different approach. There seems to be SpatialAnchor-Systems for the Unity WLT, UnityEngine.VR.WSA with WorldManager, Azure Spatial Anchors,
UnityEngine.XR.WindowsMR.WindowsMREnvironment, etc.
And unless I havent overseen it, the microsoft documentation is not really clear about which one to use and how to use it right.
I would be really thankful if someone could bring some light into this issue.
I posted this question also on forum.unity.com

Related

Could I Intercept Exit FullScreen event from octane.xam.VideoPlayer plugin (XAMARIN FORMS)?

My application works portait, ma i want fullscreen video playback even in landscape mode using the plugin mentionend above.
For this purpose I create a customrenderer to take access to native AVPlayerViewController Ios Control.
I tried in many many ways, but seems to be impossible to handle exit fullscreen event. In that method i want to force layout portrait. I have the code for reset orientation already implemented but the problem is to put the code in the right place.
Any other that faced the same issue??
I tried to search for something useful in AVPlayerView(not accessible), AVPlayerVideoController, AVPlayerCurrentItem etc
Any ideas?
Thanks you in advance.
I have translated the OC code to C# in this link for you, see the following codes:
using Foundation;
using CoreGraphics;
playerViewController = new AVPlayerViewController();
playerViewController.ContentOverlayView.AddObserver(this, new NSString("bounds"), NSKeyValueObservingOptions.New | NSKeyValueObservingOptions.Old , IntPtr.Zero);
public override void ObserveValue(NSString keyPath, NSObject ofObject, NSDictionary change, IntPtr context)
{
base.ObserveValue(keyPath, ofObject, change, context);
if(ofObject == playerViewController.ContentOverlayView)
{
if(keyPath == "bounds")
{
NSValue oldRect = change.ValueForKey(new NSString("NSKeyValueChangeOldKey")) as NSValue;
NSValue newRect = change.ValueForKey(new NSString("NSKeyValueChangeNewKey")) as NSValue;
CGRect oldBounds = oldRect.CGRectValue;
CGRect newBounds = newRect.CGRectValue;
bool wasFullscreen = CGRect.Equals(oldBounds, UIScreen.MainScreen.Bounds);
bool isFullscreen = CGRect.Equals(newBounds, UIScreen.MainScreen.Bounds);
if(isFullscreen && !wasFullscreen)
{
if(CGRect.Equals(oldBounds,new CGRect(0,0,newBounds.Size.Height, newBounds.Size.Width)))
{
Console.WriteLine("rotated fullscreen");
}
else
{
Console.WriteLine("entered fullscreen");
}
}
else if(!isFullscreen && wasFullscreen)
{
Console.WriteLine("exited fullscreen");
}
}
}
}

Unity Vuforia Google VR - Can't make onPointerEnter to GameObject change material for itself

I have two 3d buttons in my scene and when I gaze into any of the buttons it will invoke OnPointerEnter callback and saving the object the pointer gazed to.
Upon pressing Fire1 on the Gamepad I apply materials taken from Resources folder.
My problem started when I gazed into the second button, and pressing Fire1 button will awkwardly changed both buttons at the same time.
This is the script I attached to both of the buttons
using UnityEngine;
using UnityEngine.EventSystems;
using Vuforia;
using System.Collections;
public class TriggerMethods : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
Material _mat;
GameObject targetObject;
Renderer rend;
int i = 0;
// Update is called once per frame
void Update () {
if (Input.GetButtonDown("Fire1"))
TukarMat();
}
public void OnPointerEnter(PointerEventData eventData)
{
targetObject = ExecuteEvents.GetEventHandler<IPointerEnterHandler>(eventData.pointerEnter);
}
public void OnPointerExit(PointerEventData eventData)
{
targetObject = null;
}
public void TukarMat()
{
Debug.Log("Value i = " + i);
if (i == 0)
{
ApplyTexture(i);
i++;
}
else if (i == 1)
{
ApplyTexture(i);
i++;
}
else if (i == 2)
{
ApplyTexture(i);
i = 0;
}
}
void ApplyTexture(int i)
{
rend = targetObject.GetComponent<Renderer>();
rend.enabled = true;
switch (i)
{
case 0:
_mat = Resources.Load("Balut", typeof(Material)) as Material;
rend.sharedMaterial = _mat;
break;
case 1:
_mat = Resources.Load("Khasiat", typeof(Material)) as Material;
rend.sharedMaterial = _mat;
break;
case 2:
_mat = Resources.Load("Alma", typeof(Material)) as Material;
rend.sharedMaterial = _mat;
break;
default:
break;
}
}
I sensed some logic error and tried making another class to only manage object the pointer gazed to but I was getting more confused.
Hope getting some helps
Thank you
TukarMat() is beeing called on both buttons when you press Fire1. If targetObject is really becoming null this should give an error on first button since it's trying to get component from a null object. Else, it'll change both as you said. Make sure OnPointerExit is beeing called.
Also, it seems you are changing the shared material.
The documentation suggests:
Modifying sharedMaterial will change the appearance of all objects using this material, and change material settings that are stored in the project too.
It is not recommended to modify materials returned by sharedMaterial. If you want to modify the material of a renderer use material instead.
So, try changing the material property instead of sharedMaterial since it'll change the material for that object only.

C# WPF Navigate to FlowDocument in a Frame: Need to set ViewMode=Scroll

When navigating to a FlowDocument in a Frame, the FlowDocumentReader defaults to ViewMode=Page. I need to get a reference to the FlowDocumentReader so that I can set the ViewMode property to Scroll.
I can get a reference to the FlowDocument object by casting the Frame's Content property to a FlowDocument, but I cannot find a reference to the FlowDocumentReader that is instantiated when I navigate to the document.
I understand that the user can easily click on the scroll view button in the FlowDocumentReader, but I should be able to do this programmatically.
I was barking up the wrong tree, literally! The answer to my question was that the FlowDocumentReader is part of the Visual tree. I had to go hunting for it. There are probably more elegant ways to do this, but this one worked:
static public void SetReaderModeToScroll(Visual myVisual)
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(myVisual); i++)
{
// fetch the child
Visual childVisual = (Visual)VisualTreeHelper.GetChild(myVisual, i);
// attempt to cast it to a FlowDocumentReader
try
{
FlowDocumentReader reader = (FlowDocumentReader) childVisual;
// if we get this far, we've found the reader
reader.ViewingMode = FlowDocumentReaderViewingMode.Scroll;
return;
}
// catch the exception if it doesn't work
catch (Exception e)
{
}
// Drill down another level and keep looking
SetReaderModeToScroll(childVisual);
}
}

How to use ABPeoplePickerNavigationController in MonoTouch to pick a specific email address or phone number of a contact?

I have been using the ABPeoplePickerNavigationController in a project, written in MonoTouch, to pick a specific email address or phone number of a contact.
The code set a delegate, and in the delegate I implemented the ShouldContinue method, and retrieved the contact using the Handle property of all contacts. Unfortunately, it looks like something changed, or that I used undocumented features, or that I was simply lucky, because now when I'm in the process of updating the app for iPhone 5, the code no longer works.
Edit: Ok, my initial thoughts was that this was caused by changes in MonoTouch, since there has been quite a few updates since I last worked on this app. However, I now removed it from my device and downloaded the version I have on the app store, and it crashes in the same manner, null reference exception.
This means it is an iOS upgrade that made my code non-functional.
The goal of my code:
Pick a person's specific email address, not just the person, but navigating into the details of the person, and selecting a specific email address or telephone number.
The below code deals with phone numbers only, the email code looks 95% similar.
Here is the code that constructs the picker:
var picker = new ABPeoplePickerNavigationController();
picker.Init();
picker.DisplayedProperties.Clear();
picker.DisplayedProperties.Add(ABPersonProperty.FirstName);
picker.DisplayedProperties.Add(ABPersonProperty.Phone);
var del = new PhonePickerDelegate();
picker.Delegate = del;
Here is the delegate class:
private class PhonePickerDelegate : ABPeoplePickerNavigationControllerDelegate
{
public override bool ShouldContinue(ABPeoplePickerNavigationController peoplePicker, IntPtr selectedPerson, int propertyId, int identifier)
{
peoplePicker.DismissModalViewControllerAnimated(true);
// THE NEXT LINE IS THE ONE THAT NO LONGER WORKS
var contact = peoplePicker.AddressBook.SingleOrDefault(s => s.Handle == selectedPerson) as ABPerson;
using (var phones = contact.GetPhones())
{
int index = phones.GetIndexForIdentifier(identifier);
var phone = phones.GetValues()[index];
var name = (contact.FirstName + " " + contact.MiddleName).Trim() + " " + contact.LastName;
Selected(name + ": " + phone);
}
return false;
}
public override void Cancelled(ABPeoplePickerNavigationController peoplePicker)
{
peoplePicker.DismissModalViewControllerAnimated(true);
}
}
Unfortunately this code no longer finds the correct contact, as none of the contacts has a Handle value that corresponds to the selectedPerson IntPtr value.
My questions are these:
How can I fix the above code?
Can I fix the above code?
Is there some other class/method/delegate/event or whatnot I should be using instead?
You could do something like the following:
Note that AppDelegate.navigation would be your current NavigationController
using MonoTouch.AddressBookUI;
using MonoTouch.AddressBook;
ABPeoplePickerNavigationController _contactController = new ABPeoplePickerNavigationController ();
AppDelegate.navigation.PresentViewController (_contactController, true, null);
_contactController.Cancelled += delegate {
AppDelegate.navigation.DismissViewController (true, null);
return;
};
_contactController.SelectPerson += delegate(object sender, ABPeoplePickerSelectPersonEventArgs e) {
_importedContact = e.Person;
AppDelegate.navigation.DismissViewController (true, delegate {
// What to do when you dismiss the picker here.
});
};
e.Person is only going to give you the whole contact. You would want to do something like:
e.Person.GetEmails().FirstOrDefault
Hope this helps

How to get the tab ID from url in DotNetNuke

I have an url (e.g. http://localhost/Aanbod/Pagina.aspx) and I want to know the tab id, so I can make a friendly url with query (e.g. http://localhost/Aanbod/Pagina/QueryKey/QueryValue/).
Anyone has an idea?
Edit:
I'm not on the page itself. Want to know it from any page possible.
The url does not contain the tab id itself, so it can't be extracted.
if Pagina.aspx is a page in dotnet nuke like Home or Getting Started then you can find the tab id by
DotNetNuke.Entities.Tabs.TabController objTab = new DotNetNuke.Entities.Tabs.TabController();
DotNetNuke.Entities.Tabs.TabInfo objTabinfo = objTab.GetTabByName("Pagina", this.PortalId);
int Tabid = objTabinfo.TabID;
Well, this post is a little bit old, and I don't know if someone still looks for a solution. I had this problem recently and here is the pieces of code I wrote to solve it:
public int GetTabIDFromUrl(string url, int portalID)
{
int getTabIDFromUrl = 0;
// Try the "old" way with the TabID query string
if (url.ToLower().IndexOf("tabid") > 0)
{
Int32.TryParse(Regex.Match(url, "tabid[=/](\\d+)", RegexOptions.IgnoreCase).Groups[1].Value, out getTabIDFromUrl);
}
// When there is no result (because of advanced or human friendly or whatever Url provider)
if (getTabIDFromUrl == 0)
{
TabCollection tabs = TabController.Instance.GetTabsByPortal(portalID);
foreach (KeyValuePair<int, TabInfo> k in tabs)
{
TabInfo tab = k.Value;
if (tab.FullUrl.StartsWith(url))
{
getTabIDFromUrl = tab.TabID;
break;
}
}
}
return getTabIDFromUrl;
}
This could be a pain with sites that have a lot of pages, therefore it could be useful if you have some additional information to shrink the list that you have to loop through - e.g. a ModuleId of a module that is placed on this tab:
public int GetTabIDFromUrl(string url, int moduleID, int portalID)
{
int getTabIDFromUrl = 0;
// Try the "old" way with the TabID query string
if (url.ToLower().IndexOf("tabid") > 0)
{
Int32.TryParse(Regex.Match(url, "tabid[=/](\\d+)", RegexOptions.IgnoreCase).Groups[1].Value, out getTabIDFromUrl);
}
// When there is no result (because of advanced or human friendly or whatever Url provider)
if (getTabIDFromUrl == 0)
{
IList<ModuleInfo> modules = ModuleController.Instance.GetTabModulesByModule(moduleID);
foreach (ModuleInfo module in modules)
{
TabInfo tab = TabController.Instance.GetTab(module.TabID, portalID);
if (tab.FullUrl.StartsWith(url))
{
getTabIDFromUrl = tab.TabID;
break;
}
}
}
return getTabIDFromUrl;
}
Hope that helps someone...
Happy DNNing!
Michael
I hope this will solve your issue
http://www.willstrohl.com/Blog/EntryId/66/HOW-TO-Get-DNN-TabInfo-page-object-from-TabId
Sorry, my bad!!
Here is your answer
http://www.dotnetnuke.com/Resources/Forums/forumid/118/threadid/89605/scope/posts.aspx :)

Resources