microsoft / MixedRealityCompanionKit

This is a MixedRealityToolkit style repository for code bits and components that may not run directly on Microsoft HoloLens or immersive headsets but instead pair with them to build experiences.
MIT License
594 stars 288 forks source link

Use with C# UWP or unity generated project #4

Open danglingneuron opened 7 years ago

danglingneuron commented 7 years ago

I tried adding the holographic remoting nugets to a Unity generated C#/XAML/D3D project but those dlls are probably not compatible. I also tried to generate IL2CPP from Unity to get a C++ D3D UWP project - but this companion is barebones C++/D3D. I am lost on how one would actualy run a Unity3D Holographic app on windows 10 box and be able to remote to HoloLens.

Before I start getting into this code and tryng to retrofit it into teh unity generated code, Is this possible and needs some work from my end or are there any clear roadblocks that you guys are aware of?

angelaHillier commented 7 years ago

Hi @danglingneuron, Right now, Unity Remoting will only work while you are running your app inside of Unity. I'm currently working to get the Remoting APIs accessible in C#. My first goal is to port the RemotingHostSampleUWP project to C#/SharpDX. I'm using C++/CX to wrap some of the basic functionality from the HolographicStreamerHelpers class. The process is slow-going, as I'm new to most of this (Remoting, C++/CX, and SharpDX). If successful, the next challenge will be to try modifying a Unity app to work with the Remoting APIs (like you, my initial approach will be to modify the generated code). I've been warned that this might not be straight-forward or even possible, but I'm hoping to try after I get a basic interop layer written and the C# sample working.

danglingneuron commented 7 years ago

Thank you for the response. Yes, so far I am of the opinion that this is probably not possible. The reason is that Unity generated code needs the "structure" in a certain way and takes control of resources App/FrameworkView/SwapChain etc etc and they require objects passed into teh AppCallBack "blackbox". When you look at the Holographic Remoting helper classes, they also say to structure the code a certain way and they take control of resources by passing stuff to their blackbox. The structure is very conflicting right now as far as I can see.

thomsan commented 7 years ago

@angelaHillier Any news on the Unity/C# support?

WangYifang commented 7 years ago

Has the problem been settled?

whohlfeld commented 6 years ago

Has this been solved? We are to trying to adapt Holographic Remoting to our App written in C# with Unity as well so this would be a big help!

Arlorean commented 6 years ago

We managed to get this working in Unity within a UWP app. We didn't use any standard stereo optimizations like single pass, we brute force rendered to left and right eye textures. We took the ID3D11Texture2D pointers from the Unity created textures and called this code to copy the textures into the texture array that the Holographic Remoting SDK wanted:

auto backBuffer = pCameraResources->GetBackBufferTexture2D();

context->CopySubresourceRegion(backBuffer, 0, 0, 0, 0, leftTexture, 0, nullptr); // Copy Unity texture to shared texture
context->CopySubresourceRegion(backBuffer, 1, 0, 0, 0, rightTexture, 0, nullptr); // Copy Unity texture to shared texture

It's not pretty or efficient but it works... mostly. We found the Holographic Remoting to be less than stable. It would stop streaming video at some points and require a restart. But when it works we've had customers say it's the best experience they've ever had on the Hololens.