Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Intel RealSense support in Unity 5.3.x WebGL? DLLNotFoundException

Discussion in 'WebGL' started by AnthonyPalma, Jan 18, 2016.

  1. AnthonyPalma

    AnthonyPalma

    Joined:
    Aug 11, 2013
    Posts:
    128
    Hey everyone,

    I built a RealSense game demo for Intel's RealSense App Challenge last year, and I'd like to host it on the web via Unity's WebGL exporter for anyone with a RealSense to enjoy. I can build to WebGL and the game runs, but the RealSense (F200 version) doesn't get activated and turn on in the WebGL build.

    I saw that Webcams are now enabled in Unity 5.3, so is there a way for me to enable the RealSense as well? Hopefully it's just a matter of sending it the signal to activate? Pretty noob on this peripheral stuff, especially in WebGL, so any help would be appreciated!

    Edit: Tried just running the RealSense as a webcam via WebcamTexture to put the RGB feed on a plane in-game, and while it worked in the Editor, again the RealSense camera did not even turn on from the WebGL build, let alone show the feed.
     
    Last edited: Jan 18, 2016
  2. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    What are the requirements for RealSense? Just a webcam video feed ?

    To start, have you tried to simply create a WebCamTexture and render the video onto a Quad or UI element on screen ?
     
  3. AnthonyPalma

    AnthonyPalma

    Joined:
    Aug 11, 2013
    Posts:
    128
    Hey Marco,

    Not sure if you saw my edit to my original post above, but yes I did try that; it works in the editor (shows the RGB feed on a plane), but it's the same result in the WebGL build: the camera never activates.

    Is there something special I have to do to activate a webcam via WebGL? I saw a thread where in the WebPlayer you had to ask the user for permission; do I have to do that too to activate the webcam?

    As for the RealSense itself, it's a depth camera like a Kinect that's meant to be used up close. They have a Unity plugin which works on desktop.
     
  4. AnthonyPalma

    AnthonyPalma

    Joined:
    Aug 11, 2013
    Posts:
    128
    Ok, I'm convinced the problem is that I'm not properly requesting authorization from the user to enable the webcam/microphone in the game window. Here's my code:

    Code (CSharp):
    1. IEnumerator AskPermission() {
    2.         yield return Application.RequestUserAuthorization(UserAuthorization.WebCam | UserAuthorization.Microphone);
    3.         if(Application.HasUserAuthorization(UserAuthorization.WebCam | UserAuthorization.Microphone))
    4.         {
    5.             WebCamDevice[] devices = WebCamTexture.devices;
    6.             string deviceName = "none";
    7.             for(int i = 0; i < devices.Length; i++)
    8.             {
    9.                 if(devices[i].name.Contains("RGB"))//RealSense has 3 inputs, so we want the RGB one for the webcamTexture
    10.                     deviceName = devices[i].name;
    11.             }
    12.  
    13.             print("deviceName = "+deviceName);
    14.  
    15.             WebCamTexture webcamTexture = new WebCamTexture(deviceName);
    16.             Renderer renderer = GetComponent<Renderer>();
    17.             renderer.material.mainTexture = webcamTexture;
    18.             webcamTexture.Play();
    19.         }
    20.     }
    I've tried triggering this both in Start() and when a button is pressed, but all it does is turn the webcamTexture black and I never get a prompt from my browser. Am I doing something wrong?
     
  5. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    Actually, Application.RequestUserAuthorization / HasUserAuthorization are only available on the webplayer. It might be possible to implement them on Unity webgl but it's something we haven't looked into yet.

    The user will be asked to authorize the page to use the webcam as soon as you create and Play the WebCamTexture.
     
  6. AnthonyPalma

    AnthonyPalma

    Joined:
    Aug 11, 2013
    Posts:
    128
    Got it. Oddly enough, the first thing I tried was to implement the latter part of that code on its own:
    Code (CSharp):
    1. WebCamDevice[] devices = WebCamTexture.devices;
    2. string deviceName = "none";
    3. for(int i = 0; i < devices.Length; i++)
    4. {
    5. if(devices[i].name.Contains("RGB"))//RealSense has 3 inputs, so we want the RGB one for the webcamTexture
    6.       deviceName = devices[i].name;
    7. }
    8.  
    9. print("deviceName = "+deviceName);
    10.  
    11. WebCamTexture webcamTexture = new WebCamTexture(deviceName);
    12. Renderer renderer = GetComponent<Renderer>();
    13. renderer.material.mainTexture = webcamTexture;
    14. webcamTexture.Play();
    But this yields the same result: I never get a pop-up asking to authorize the webcam in WebGL, and consequently the webcam never turns on. Am I missing code here that would generate that pop-up?
     
  7. AnthonyPalma

    AnthonyPalma

    Joined:
    Aug 11, 2013
    Posts:
    128
    Quick update: It looks like the problem might be that Unity WebGL isn't seeing an important RealSense DLL file. I'm getting:
    I can now actually call the webcam, get the user permission dialog, and get it to show my camera feed on the plane via WebCamTexture, but the RealSense won't do depth detection (even though that feed is active), presumably due to this DLL not being found.

    So now my question is: how do I include this DLL into my WebGL build if it doesn't work now? it's currently in the Plugins folder and works fine on desktop builds.

    Thanks for all the help!

    Edit: DLL files in question are attached if it helps.

    Tagging @jonas echterhoff as he seems to be a WebGL expert as well :)
     

    Attached Files:

    Last edited: Jan 19, 2016
  8. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    That is not a managed DLL, is it ? Native Windows plugins cannot be used in Unity WebGL. If you have the c/c++ sources though you could drop them in the projects and Unity will compile them as part of the build process.
     
  9. AnthonyPalma

    AnthonyPalma

    Joined:
    Aug 11, 2013
    Posts:
    128
    Thanks for the note! How would I be able to tell if they're managed vs. native? I'm guessing they're native since it won't be found on the WebGL build, but their Unity Toolkit does come with a "Plugins.managed" folder (screenshot attached), so I'm hopeful that there's some way to still get this working. I'm also able to find Visual Studio .sln files with the DLL's name but not source code, so I'm opening the project to see what I can do.

    Do you have any tips on what sources I'd need and what to do with them in Unity? Is it literally just drop them in?

    Thanks again!
     

    Attached Files:

  10. yuliyF

    yuliyF

    Joined:
    Nov 15, 2012
    Posts:
    188
    DllNotFoundException: Unable to load DLL 'MathFuncsDll': The specified module could not be found.

    What, Marko? WebGL can't use DLLs - ? it's a joke? It's unacceptable !!!
     
  11. AnthonyPalma

    AnthonyPalma

    Joined:
    Aug 11, 2013
    Posts:
    128
    @yuliyF as I understand it now, browsers don't allow native DLLs for security reasons. The only way around it is to load the source code for the DLL into Unity instead of the DLL itself, but I don't have the source for the RealSense DLL :( I've contacted my reps at Intel to try and obtain it, though. Will post here if I make progress.
     
  12. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    Managed DLLs work just fine.
     
  13. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    you are correct.

    the problem is, that in the browser we run javascript, not native code. So, when it comes to managed DLL, we have a build pipeline for translating that into LLVM bitcode, then to asm.js (we published a few blog posts about that)...but not for native DLLs and certainly browser vendors don't allow to run native code in the browser.
     
  14. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    553
    The RealSense DLLs use hardware specific code that you can't be reach from the web, for security reasons...

    But I know that there's a RealSense JavaScript SDK - so maybe a solution for you we'll be to implement it yourself to unity.
     
  15. AnthonyPalma

    AnthonyPalma

    Joined:
    Aug 11, 2013
    Posts:
    128
    Thanks guys! I've reached out to Intel for some guidance, will report here if I hear anything.
     
  16. yuliyF

    yuliyF

    Joined:
    Nov 15, 2012
    Posts:
    188
  17. AnthonyPalma

    AnthonyPalma

    Joined:
    Aug 11, 2013
    Posts:
    128
  18. 52cwalk

    52cwalk

    Joined:
    Nov 23, 2013
    Posts:
    15

    hello
    I use the webcamtexture in webgl by unity3d 5.3.2,but the camera texture is black,why?
    my code:
    WebCamTexture webcamTexture = new WebCamTexture();
    Renderer renderer = GetComponent<Renderer>();
    renderer.material.mainTexture = webcamTexture;
    webcamTexture.Play();
     
  19. ge53

    ge53

    Joined:
    Feb 19, 2017
    Posts:
    15
     
  20. ge53

    ge53

    Joined:
    Feb 19, 2017
    Posts:
    15
    Did you ever get this to work for you? I am starting with the realsense sr300...thanks.
     
  21. svizcay

    svizcay

    Joined:
    Oct 26, 2015
    Posts:
    28
    Could you elaborate a little bit more about "dropping c++ code into unity and getting it compile it".
    Is there any special folder to drop c++ code?
    I have a quite complex c++ library with some dependencies and I have a working dll out of it.

    Right now, the native plugin works well in android and desktop but I also need it in WebGL but the dll doesn't work there.