Metadata picking in VR

Hi,

I’m quite new in usin Unity with Cesium.
I’m trying to use the Metadata Picking skript in a VR-Scene, but I’m not able to get it working. Does anyone have any experiences with this topic? I’m sure I need to change the skript in any way and also need to do something with the XR interactions, but at the moment I’m totally clueless.
Thanks in advance.

Hello, metadata picking in VR can be done by modifying the VR01_CesiumDenver scene in CesiumUnitySamples.

In the scene, under XR Origin → Camera Offset → Right Hand Controller, enable the XR Interactor Line Visual component. This allows you to see the ray you are pointing.

Next create a game object and add the Cesium Metadata Picking script to it.

Modify the script to get a reference to the right hand controller game object, and the XR Ray Interactor component and also the input action property, i.e:

{
    // The GameObject with the UI to enable / disable depending on
    // whether metadata has been picked.
    public GameObject metadataPanel;

    // The text to display the metadata properties.
    public Text metadataText;

    public GameObject righthand;
    XRRayInteractor xrayInteractor;
    public InputActionProperty m_SelectAction;

Then in the editor, plug in the values:
image

For the Input Action Property, I chose XRI RightHandInteraction/Select, which maps to the side button (grip) on the right controller.

In the start method, you want to get a reference to the xray interactor, and also enable the InputActionProperty:

xrayInteractor = righthand.GetComponent<XRRayInteractor>();

        m_SelectAction.action.Enable();

Next, we want to raycast whenever we hit the grip button, so in update, we modify it like so:

   void Update()
    {
        bool getMetadata = m_SelectAction.action.triggered;

        if (getMetadata && metadataText != null)
        {
            metadataText.text = "";

            RaycastHit hit;
            if (
            xrayInteractor.TryGetCurrent3DRaycastHit(
                out hit))
            {

I think everything should work… The only thing left is that the UI is not designed for VR… In order to show it, you can go to the CesiumMetadataUI gameobject, and change the Canvas Render mode to World Space, and move the Panel somewhere you can see.

1 Like

Thank you so much!
It works exactly as I wanted it to.