Daggerfall Unity VR with the Vive Pro

Discuss coding questions, pull requests, and implementation details.
Post Reply
User avatar
Interkarma
Posts: 5013
Joined: Sun Mar 22, 2015 1:51 am

Re: Daggerfall Unity VR with the Vive Pro

Post by Interkarma » Tue Jun 05, 2018 11:00 pm

InconsolableCellist wrote:
Tue Jun 05, 2018 10:13 pm
That works for me. It'd be fine to require an option for VR in the settings
Thank you. Here's how it works from latest commit:
  • Default UI is enabled and shown by default for regular 2D users. It is no longer rendered to an offscreen surface to better support folks with lower-end computers.
  • You can disable default UI using DaggerfallUI.Instance.EnableDefaultUserInterface = false; This will disable both Update() and Draw() for default UI stack so it basically does nothing at all. The old NonDiegeticUIOutput is completely gone.
  • From here you should still be able to add your custom UserInterfaceRenderTarget stacks and draw/present as required.
  • Custom pointer input is part-complete. You can set your input coordinates (as pixel coordinates where 0,0 is top-left corner) to the root panel using CustomMousePosition. This will propagate all the way down through panel hierarchy to leaf controls. Note this is completely untested at this time.
I still have work to do on the pointer input, mainly adding helpers to make this easier. You can possibly work with it as is but it's going to need some heavier lifting on your side. I'll put together some helpers and another demo soon.

User avatar
InconsolableCellist
Posts: 95
Joined: Mon Mar 23, 2015 6:00 am

Re: Daggerfall Unity VR with the Vive Pro

Post by InconsolableCellist » Tue Jun 05, 2018 11:44 pm

Thanks! This sounds like enough to get me going. I'll be able to take a look at it shortly. (Evening for me might be your mid-day? It's 8 PM here)

If it can handle offset coordinates and clicks I'm not sure what helpers will be necessary, but I suspect it'll become apparent.

User avatar
Interkarma
Posts: 5013
Joined: Sun Mar 22, 2015 1:51 am

Re: Daggerfall Unity VR with the Vive Pro

Post by Interkarma » Wed Jun 06, 2018 12:04 am

Sounds about right. 10am here right now. I still have a full day of work ahead. :)

User avatar
Interkarma
Posts: 5013
Joined: Sun Mar 22, 2015 1:51 am

Re: Daggerfall Unity VR with the Vive Pro

Post by Interkarma » Wed Jun 06, 2018 3:53 am

Just a heads up, I'm making a couple of changes to UserInterfaceRenderTarget to better support a full window stack and custom pointer input. It's going to be able to host a full window stack, not just a single panel.

Edit: Scratch that for now. I've hit some problems with this approach I can't overcome in the time I've permitted myself. It also required too many alterations to core which breaks my first rule. I'm working on a different approach to host individual windows in floating panels and will update you when possible.

User avatar
Interkarma
Posts: 5013
Joined: Sun Mar 22, 2015 1:51 am

Re: Daggerfall Unity VR with the Vive Pro

Post by Interkarma » Wed Jun 06, 2018 9:41 am

I'm sorry, but I need to bow out from splitting individual windows like inventory and automap to their own stack. The primary UI stack is just too embedded and interlinked across too many other systems to easily pry them all apart.

But here's everything I can do without rearchitecting huge chunks of core code - something I'm not willing to do this close to the end.
  1. Ability to create your own floating panel hierarchies supporting custom controls. This is what UserInterfaceRenderTarget provides now. You can build whatever you want into this using DagUI controls.
  2. Ability to redirect main UI stack to a custom output target. This means showing the full-blown UI to its own popup diegetic window. This can only be available while game is paused. If something throws a popup during play (e.g. a quest message popup) then the game must pause to display the main UI stack on a diegetic panel. This is exactly how the UI works in Skyrim VR, for example.
  3. And of course you can use Unity's own uGUI system and other features to create whatever custom controls you wish and interface to the same back-end data (e.g. PlayerEntity) that my UI consumes.
Of these, you should find that #1 and #3 still offer plenty of flexibility. For example, you could write a custom hand-held backpack control just to interface with what player is carrying in their bag. This won't provide the same features as full-blown inventory UI (paper doll, stat inspection, etc.) but it could still be useful for drinking a potion, dropping something, or using a magic item. Likewise you could make a cut down version of automap, or a fully VR dungeon automap the player can grab and rotate in the air in front of them. You're only really limited by what you can personally accomplish here.

The only real constraint is the primary UI stack has to remain as it is now, and you need to handle output from systems like the quest machine that send popup text out the main stack by pausing game and displaying primary stack in VR.

If you can work within these constraints and feel confident building your own custom interfaces, I think you can make the game fully playable (and then some) from your VR mod. :)

User avatar
InconsolableCellist
Posts: 95
Joined: Mon Mar 23, 2015 6:00 am

Re: Daggerfall Unity VR with the Vive Pro

Post by InconsolableCellist » Wed Jun 06, 2018 7:13 pm

That's okay, I think I can work within those constraints, and if it becomes somehow essential to have a UI feature, I'll just have to reimplement some of it myself. I think pop-up windows that pause the game won't be *bad* in VR though, and I can create custom UI panels like you said.

This is all independent of being able to pass offset coordinates into the UI windows, right? And will the compass still work, or does that need to be reverted?

User avatar
Interkarma
Posts: 5013
Joined: Sun Mar 22, 2015 1:51 am

Re: Daggerfall Unity VR with the Vive Pro

Post by Interkarma » Wed Jun 06, 2018 8:31 pm

Compass will work just like now, and I've carved out a solution for passing in coordinates. Just need to clean it up and I'll post another quick tutorial.

I'll get this posted as soon as I can.

User avatar
Interkarma
Posts: 5013
Joined: Sun Mar 22, 2015 1:51 am

Re: Daggerfall Unity VR with the Vive Pro

Post by Interkarma » Wed Jun 06, 2018 10:12 pm

Summary

From latest code, you can now redirect the primary UI stack to a custom render target. It's no longer possible to disable primary UI completely, but you can redirect the output to your own diegetic world objects.

The below example places a fixed diegetic UI canvas into the starting room in Privateer's Hold using our friend UserInterfaceRenderTarget. It will only display while game is paused (e.g. when UI is opened or something pops up), and only at this position in world. I trust you'll be able to take the concepts and convert to your needs in VR.


Code

Create a new C# script called FloatingUITest.cs and paste in following code.

Code: Select all

using UnityEngine;
using UnityEngine.UI;
using DaggerfallWorkshop.Game;
using DaggerfallWorkshop.Game.UserInterface;

[RequireComponent(typeof(UserInterfaceRenderTarget))]
public class FloatingUITest : MonoBehaviour
{
    UserInterfaceRenderTarget ui;
    Vector2 virtualMousePos = Vector2.zero;
    RawImage rawImage;
    Canvas canvas;
    Vector2 offscreenMouse = new Vector2(-1, -1);

    private void Start()
    {
        // Redirect main UI stack to our custom target and disable HUD
        ui = GetComponent<UserInterfaceRenderTarget>();
        DaggerfallUI.Instance.CustomRenderTarget = ui;
        DaggerfallUI.Instance.enableHUD = false;

        // Get references
        rawImage = GetComponent<RawImage>();
        canvas = GetComponent<Canvas>();
    }

    private void Update()
    {
        // Do nothing unless game is paused - this can happen at any time either through user input or a quest message popping up text
        // When not active, we set custom mouse position to null to release any custom position set from a prior open UI session
        // Also disabling raw image when not required here - you would manage your own output canvas in VR as needed
        if (!GameManager.IsGamePaused)
        {
            rawImage.enabled = false;
            DaggerfallUI.Instance.CustomMousePosition = null;
            return;
        }

        // Show the raw image - in VR you would bring up your diegetic output panel in front of player
        rawImage.enabled = true;

        // Setting mouse offscreen unless can resolve position below
        virtualMousePos = offscreenMouse;

        // Get rect of rawimage
        Rect rect = RectTransformUtility.PixelAdjustRect(rawImage.rectTransform, canvas);

        // Is screen position inside rectTransform? Here you would use your own means of firing a ray at target canvas from controller
        if (RectTransformUtility.RectangleContainsScreenPoint(rawImage.rectTransform, Input.mousePosition, GameManager.Instance.MainCamera))
        {
            // Get local point inside canvas
            Vector2 localPoint;
            if (RectTransformUtility.ScreenPointToLocalPointInRectangle(rawImage.rectTransform, Input.mousePosition, GameManager.Instance.MainCamera, out localPoint))
            {
                // Convert to UV coordinates inside tranform area using rect - v is raised into the 0-1 domain and inverted for 0 to be top-left
                float u = localPoint.x / rect.width + 0.5f;
                float v = 1.0f - (localPoint.y / rect.height + 0.5f);

                // We know size of render target so we can convert this into x, y coordinates
                float x = u * ui.TargetSize.x;
                float y = v * ui.TargetSize.y;

                // Set virtual mouse position into UI system
                virtualMousePos = new Vector2(x, y);
            }
        }

        // Feed custom mouse position into UI system
        DaggerfallUI.Instance.CustomMousePosition = virtualMousePos;
    }
}

World Object

Now create a GameObject in root of scene called FloatingUI and configure its Inspector exactly as below with all components and their settings. This will position it to starting cave in PH facing player when you start a game or load a save in this room.

When you hit play, face world object and open UI windows as normal. They will be redirected to the custom target along with mouse input.

floatingui-inspector.JPG
floatingui-inspector.JPG (88.33 KiB) Viewed 2605 times

Improvements

Something else we need to do is allow you to set your own scroll events and click input. But if you can get things started, I'll be able to expose these events so you can inject scrolls and clicks also.


Example

In my example the mouse is standing in for the "laser pointer" from a Vive controller. Everything is happening in world space however.

Image

User avatar
InconsolableCellist
Posts: 95
Joined: Mon Mar 23, 2015 6:00 am

Re: Daggerfall Unity VR with the Vive Pro

Post by InconsolableCellist » Thu Jun 07, 2018 1:15 am

Looking good as always! I'll be able to try this out shortly. Thanks! I hope this isn't throwing too much of a monkey wrench into planned roadmap tasks.

User avatar
mikeprichard
Posts: 757
Joined: Sun Feb 19, 2017 6:49 pm

Re: Daggerfall Unity VR with the Vive Pro

Post by mikeprichard » Thu Jun 07, 2018 1:01 pm

It's incredible that you're able to find the time and energy for these other projects in addition to your work on core development and bug fixes - just hope you're making time for some rest, too. :)

Post Reply