I need to create a UI that remains in one place while the user is able to interact with the 3D model

camera
ui
#1

I am creating a project that will have a static UI on the left and the 3D models will be on the right. My problem is that so far all the 2d objects I create are tracked and move as the glasses move. I read the recommendations to create a Canvas and set it to Worldspace and while everything is readable – I need it to not move. I need the UI to remain in one place. This will be a horizontal layout with text and information for the user to read and click on. The assets I have are primarily images. I need to be able to create a panel on the left side that holds text and buttons. Also, I should add I am building this project in Unity 2017 and C#.

0 Likes

#2

I talked with a very helpful support person and he explained to me that anything I place in the scene will be tracked because of how zCore works. Can anyone help me think of a way around this? This is for a training project so it is a very important part of the scene for the text to remain static and in one place. Thanks for any help you all can give me!

0 Likes

#3

Its certainly possible to have a UI statically placed relative to the display. The easiest way is to have your worldspace canvas locked to zcore’s viewport plane. Its a representation of where the physical display is located in virtual space. The camera frustums pivot on this plane and because of this, any objects locked to it will have the effect of sitting still on the display glass, like a typical UI.

Here’s a simple script that should help you get what you’re looking for when attached to a world space UI canvas.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using zSpace.Core;

public class canvasToViewportAlign : MonoBehaviour {

    private ZCore core;

    void Start(){
        core = GameObject.FindObjectOfType<ZCore>();
        var viewportCenter   = core.GetViewportWorldCenter();
        var viewportRotation = core.GetViewportWorldRotation();
        var viewportSizePixels = core.GetViewportSize();
        var viewportSizeMeters = core.GetViewportWorldSize();

        this.transform.position = viewportCenter;
        this.transform.rotation = viewportRotation;

        // Based on Unity document,
        // passing the meter to pixel value as scale for the canvas to fit in current screen.
        var scale = new Vector2(viewportSizeMeters.x / viewportSizePixels.x,
                                viewportSizeMeters.y / viewportSizePixels.y);

        var resolution = new Vector2(viewportSizePixels.x, viewportSizePixels.y);

        const float SmallScaleZ = 0.0002f;

        Vector3 localScale = new Vector3(scale.x, scale.y, SmallScaleZ);
        this.transform.localScale = localScale;

        var rect = this.GetComponent<RectTransform>();
        rect.sizeDelta = resolution;
        Vector2 center = new Vector2(0.5f, 0.5f);
        rect.pivot = center;
    }

	void Update () {
        transform.position = core.GetViewportWorldCenter();
        transform.rotation = core.GetViewportWorldRotation();
	}
}
0 Likes