Unity3d plugin for embedding webpages on WINDOWS is ready!

Discussion in 'Showcase' started by lubo3d, Mar 24, 2011.

  1. lubo3d

    lubo3d

    New Member

    Joined:
    Mar 23, 2011
    Messages:
    75
    UnityWebCore plugin aims to embed webpages(html including flash videos or other flash applications) into Unity3d as texture on WINDOWS.

    Following features are supported:
    • Mouse interaction fully supported, moving, scrolling and middle button utility just as common web browsers.
    • Mouse cursor changing via the content of webpage in hardware mode.
    • Keyboard input fully supported including receiving IME inputs.
    • Status callback during loading and showing webpage.
    • HTTP, HTTPS and local html following HTML4 standard are fully supported.
    • Higher performance via partly update each frame and multi-thread rendering.
    • Embedding flash into the webpage is fully supported.
    • Transparent background is fully supported.
    • Zoom In/Out the webpage view is supported.
    • Going forward, backward and refreshing the webpage are supported.
    • Executing javascript code or functions in html from Unity3d.
      And javascript in html can also call Unity3d callback functions.
      Code (csharp):
      1.    
      2.     // execute html javascript code from Unity3d C# code
      3.     public static extern void ExecuteJS(int webViewId, string javascript);    
      4.     // call javascript function in html from Unity3d C# code
      5.     public static void CallJS(int webViewId, string funcName, params  object[] arguments);  
      6.     // add Unity3d C# function callback, it can be called from javascript in html.
      7.     public static extern void AddJSCallback(int webViewId, string funcName, JSCallbackDelFunc func);
      8.  

    [​IMG]

    Limitations: The UnityWebCore plugin can only be used in Unity Windows Standalone applications.
    PS: Please read the readme file first before using this plugin.

    Demo package download.

    Project Source package download.

    Attached Files:

    Last edited: May 21, 2011
  2. bigkahuna

    bigkahuna

    Member

    Joined:
    Apr 30, 2006
    Messages:
    5,420
    Cool! Would this work Google Maps by chance? Might have to just give this a test! :)
  3. ali.00128

    ali.00128

    New Member

    Joined:
    Sep 5, 2009
    Messages:
    71
    WOWW!! This is amazing! Just checked it out! Thanks! :eek:
  4. niosop2

    niosop2

    Member

    Joined:
    Jul 23, 2009
    Messages:
    1,014
    Awesome job! A lot of people will be very thankful for this. You should put up a donate button somewhere, or add a menu item that links to a donate page, I'm sure some people would like to thank you for this with some cash.
  5. xadhoom

    xadhoom

    New Member

    Joined:
    Sep 2, 2010
    Messages:
    91
    Hey,

    Nice package, thank you for sharing! I just noticed a visual bug. When you run a movie on youtube and scroll only the flash video will scroll (tested in editor). As soon as the video left the visible area scrolling works again...

    xad

    Edit:
    It also seems that the custom hardware cursor is not resetted properly when stopping the simulation.
    Last edited: Mar 24, 2011
  6. lubo3d

    lubo3d

    New Member

    Joined:
    Mar 23, 2011
    Messages:
    75
    Thanks xad for the testing. The two problems are fixed and the new packages are uploaded!

    So have a try!

  7. 2dfxman1

    2dfxman1

    New Member

    Joined:
    Oct 6, 2010
    Messages:
    1,065
    Sweet, now I can design my hud in html
  8. appels

    appels

    Member

    Joined:
    Jun 25, 2010
    Messages:
    2,657
    very nice work indeed.
    i tested a live video stream from the net through flash app and it also works, only the sound from the stream keeps coming in after i've stopped the scene. Maybe some thread that keeps running.
  9. pixelsteam

    pixelsteam

    Member

    Joined:
    May 1, 2009
    Messages:
    670
    Any chance of this being made for us Unity OSX users?
  10. lubo3d

    lubo3d

    New Member

    Joined:
    Mar 23, 2011
    Messages:
    75

    appels,

    You can add some code in UnityWebView class to clean up the webivew after stop the Unity Game.
    void OnApplicationQuit()
    {
    UnityWebCore.DestroyView(m_TextureID);
    }

    Also you can download the lastest package for the update.
    Thanks for the complain:)
  11. 2dfxman1

    2dfxman1

    New Member

    Joined:
    Oct 6, 2010
    Messages:
    1,065
    What rendering engine does it use? The one in IE?
  12. lubo3d

    lubo3d

    New Member

    Joined:
    Mar 23, 2011
    Messages:
    75
    Currently we don't have the plan.
    In my mind, there might not be many users because OSX application should be convinient instead of extensible.
  13. lubo3d

    lubo3d

    New Member

    Joined:
    Mar 23, 2011
    Messages:
    75
    Webkit!
  14. appels

    appels

    Member

    Joined:
    Jun 25, 2010
    Messages:
    2,657
    wasn't realy complaining lol, it's a great tool.
    I'll grab the update.
  15. 2dfxman1

    2dfxman1

    New Member

    Joined:
    Oct 6, 2010
    Messages:
    1,065
    Then why isn't it on osx?
  16. appels

    appels

    Member

    Joined:
    Jun 25, 2010
    Messages:
    2,657
    yep that fixed it, thanks :)
  17. Codster

    Codster

    New Member

    Joined:
    Apr 27, 2010
    Messages:
    440
    OH man that looks cool. One question though, I know it was not in you feature list but does other types of input work? Like mic, webcam, typing ect.
  18. lubo3d

    lubo3d

    New Member

    Joined:
    Mar 23, 2011
    Messages:
    75
    King,

    Actually this plugin embeds one web browser into Unity. So all the flash application which can run in common web browsers shall also work via this plugin.

    So just go ahead to test your mic, webcam and other application...:D
  19. lubo3d

    lubo3d

    New Member

    Joined:
    Mar 23, 2011
    Messages:
    75
    Yes, if we can hear more voice shouting for the osx version, we can make the plan!:)
  20. cemC

    cemC

    New Member

    Joined:
    Dec 23, 2010
    Messages:
    211
    Good work. Very impressing
  21. cemC

    cemC

    New Member

    Joined:
    Dec 23, 2010
    Messages:
    211
    we may get webPlayer builds or it just works on standalone?
  22. MrDude

    MrDude

    Member

    Joined:
    Sep 21, 2006
    Messages:
    1,866
    I have been asking for an OSX version ever since the release of U3 :( I just got one working and then like 3 days later I got U3 and it no longer works...

    Please, OSX version +1 :)
  23. Fenrisul

    Fenrisul

    Member

    Joined:
    Jan 2, 2010
    Messages:
    446
    This would be ridiculously powerful on iOS :X HTML5 -> Unity portal
  24. Tinus

    Tinus

    Member

    Joined:
    Apr 6, 2009
    Messages:
    381
    Good work! It seems to run very in a very slick fashion, with low performance overhead. MacOS port would be appreciated by a lot of people, I'm sure. After seeing how Wolfire are doing their entire GUI with awesomium I've been on the verge of trying something like it myself.
  25. lubo3d

    lubo3d

    New Member

    Joined:
    Mar 23, 2011
    Messages:
    75
    Thanks to the optimization of rendering and javascript interaction in UnityWebCore, entire UI solution with pure webpages(remote or local) becomes practical.
    Also we have such kind of 3D application using 50+ webpages as it's UI and some embedded materials. So you can have a try.
    If you works only on OSX, you might have to do it yourself or wait us for the porting in the near future.
  26. blackant

    blackant

    Member

    Joined:
    Jun 18, 2009
    Messages:
    325
    could we play unity game inside this webembed ?
    and could we watch this wbembed inside a webemebded inside an other web embed insid an other web embed inside an other ... ???
  27. shabazzster

    shabazzster

    New Member

    Joined:
    Mar 17, 2010
    Messages:
    105
    I haven't tested it yet, and its defiantly one of those dream plugins -good work!

    But, if it doesn't work for both windows and the Mac then no matter how cool it is -- it's still considered 2000-and-Late.

    That's just the standards of software development these days especially for anything having to do with Unity IMO :).
  28. lubo3d

    lubo3d

    New Member

    Joined:
    Mar 23, 2011
    Messages:
    75
    Currently the windows standalone unity3d application can embed the webpages which can embed another unity webpage scene:).
    However for the security reason Unity doesn't support native C++ dll plugin. So unless Unity takes UnityWebCore into its release package, the unity webpage scene can't embed webpages via UnityWebCore.
  29. xadhoom

    xadhoom

    New Member

    Joined:
    Sep 2, 2010
    Messages:
    91
    Great,

    I just faced two new issues with the latest package. When building from the given project:
    1. I don´t see the mouse cursor at all when over the window.
    2. The browser texture lacks colours (just b/w).

    Keep up the good work! Thank you for this project. ;-)
  30. lubo3d

    lubo3d

    New Member

    Joined:
    Mar 23, 2011
    Messages:
    75
    xad,

    Pls read the readme file beside the project files. You might want to copy the cursor folder manually to the built exe.
    And the name of the executable file could only be "UnityWebCoreDemo" in order to see all the features.
    If you want to build the plugin into your own application, please contact the email in the readme file.
  31. lubo3d

    lubo3d

    New Member

    Joined:
    Mar 23, 2011
    Messages:
    75
    Sorry for the mistake in my explanation. Since Unity3d npp plugin doesn't support transparent mode as flash, it can only show in windowed mode. So Unity3d webpage scene(*.unity3d) can't be embedded into the the web browser brought by UnityWebCore:(
  32. xadhoom

    xadhoom

    New Member

    Joined:
    Sep 2, 2010
    Messages:
    91
    *doh* Never mind... ;-)
  33. xadhoom

    xadhoom

    New Member

    Joined:
    Sep 2, 2010
    Messages:
    91
    I´m not sure if this is a real issue. If the browser shows a dark image overlapping the top of the border it seems that a few pixels at the top are still white. Its slightly visible in the demo.
  34. xadhoom

    xadhoom

    New Member

    Joined:
    Sep 2, 2010
    Messages:
    91
    One more thing:
    I don´t see a way to define the internal update rate of the browser buffer. Although I have 1000 FPS a youtube video or scrolling looks laggy. I understand that decreasing the update rate improves general system responseness etc. still it would be nice to be able to set it manually.

    xad
  35. fjam100

    fjam100

    New Member

    Joined:
    Dec 2, 2010
    Messages:
    2
    Great job!

    I guess this is different, but

    Would it be possible to embed html into an object?
  36. lubo3d

    lubo3d

    New Member

    Joined:
    Mar 23, 2011
    Messages:
    75
    See the last argument of UnityWebCore.CreateView(...).
  37. lubo3d

    lubo3d

    New Member

    Joined:
    Mar 23, 2011
    Messages:
    75
    The html just offers one Texture2D texture, you can set to any object you like. Also you might want to translate the mouse position yourself depending on the shape of object you used.
  38. Neodrop

    Neodrop

    Member

    Joined:
    Oct 24, 2008
    Messages:
    1,340
    Thank you for sharing.
  39. lubo3d

    lubo3d

    New Member

    Joined:
    Mar 23, 2011
    Messages:
    75
    MrDude,

    I noticed that someone had released another plugin named "htmlTexture" which runs on OSX. But The link seems broken, so does anyone have that plugin? and how was that plugin?

    If this plugin can still work, the OSXers can take it into your solution.
  40. lubo3d

    lubo3d

    New Member

    Joined:
    Mar 23, 2011
    Messages:
    75
    I tested the flash webcam application via UnityWebCore. It works well.
    See the attached image.
    $flashcamera.jpg
  41. Sarper Soher

    Sarper Soher

    Member

    Joined:
    Mar 10, 2009
    Messages:
    637
    Great plugin lubo3d, any possibility to add the ability to use the plugin in a webplayer in the future? And if not, could you please tell us why it's not possible?
  42. lubo3d

    lubo3d

    New Member

    Joined:
    Mar 23, 2011
    Messages:
    75
    Mortiis,

    UnityWebCore uses the fastest web engine WebKit as it's core. It's written in C++. However for the security reason Unity doesn't support native C++ dll plugin in webplayer export.
    So UnityWebCore can't be used in webplayer unless Unity takes UnityWebCore into its release package:)

    Another possibility is using other web3d engine instead of Unity.
    See the link for another web3d engine embedding webpages as texture.
    http://player.youku.com/player.php/sid/XMjUwMjY0MzI4/v.swf
    Last edited: Mar 28, 2011
  43. reissgrant

    reissgrant

    New Member

    Joined:
    Aug 20, 2009
    Messages:
    726
    It appears that you are using setPixels for the entire texture. Do you plan to incorporate rect rendering, where you only render the rect of the portion of the screen that has changed?

    *Edit I will add though that this is great, btw. And setpixels is really slow, but unfortunately the only way to do this sort of thing, because Unity will not allow you to grab the device pointer for direct texture access on the memory card...
  44. lubo3d

    lubo3d

    New Member

    Joined:
    Mar 23, 2011
    Messages:
    75
    Currently setPixels is the only way to batch write the teture buffer in Unity3D. Rect rendering is done in UnityWebCore internally so that the performance is more or less acceptable now.

    It will be great if Unity can provide the API to access the texture buffer directly from the memory of graphic card. That will significantly improve the performace for the texture manipulating plugins.
  45. reissgrant

    reissgrant

    New Member

    Joined:
    Aug 20, 2009
    Messages:
    726
    If you are feeling adventurous, you can access the texture memory directly with openGL, however you are stuck using only openGL and not directX.
  46. lubo3d

    lubo3d

    New Member

    Joined:
    Mar 23, 2011
    Messages:
    75
    That would be one way to have a try. Thanks, reissgrant!
  47. xlevel

    xlevel

    New Member

    Joined:
    Jan 5, 2011
    Messages:
    2
    I can't play flash movie. Appears also the different all flash to be being the same.
    watch below screen shot

    [​IMG]
  48. lubo3d

    lubo3d

    New Member

    Joined:
    Mar 23, 2011
    Messages:
    75
    xlevel,

    You might want to download and install the latest flashplayer first and then watch the youtube flash movies in Unity.
    Just click to "Download it from Aobe", it will navigate to your browser automatically.

    If you still account this problem, you should try your youtube link in Google Chrome or FireFox to see if it works.
    UnityWebCore behaves the same as Google Chrome:)
  49. xlevel

    xlevel

    New Member

    Joined:
    Jan 5, 2011
    Messages:
    2
    i tried on three browsers, explorer, crom, firefox. On Explorer and Crom, flash movie play well without fash install.
    But the same bug appeard on firefox. After flash install, it goes well on Unity.
    it is a problem that is doesn't go well in main browsers like firefox. is there any other way updating plugin on webkit?
  50. lubo3d

    lubo3d

    New Member

    Joined:
    Mar 23, 2011
    Messages:
    75
    Actually following code snippet already assign image data to a texture directy to OpenGL:

    Code (csharp):
    1.  
    2.         // Create texture that will be updated in the plugin
    3.         m_Texture = new Texture2D (width, height, TextureFormat.ARGB32, false);
    4.         // Create the pixel array for the plugin to write into at startup    
    5.         m_Pixels = m_Texture.GetPixels (0);
    6.         // "pin" the array in memory, so we can pass direct pointer to it's data to the plugin,
    7.         // without costly marshaling of array of structures.
    8.         m_PixelsHandle = GCHandle.Alloc(m_Pixels, GCHandleType.Pinned);
    9.  
    10.         UpdateTexture (m_PixelsHandle.AddrOfPinnedObject(), m_Texture.width, m_Texture.height, Time.time);
    11.         m_Texture.SetPixels (m_Pixels, 0);
    12.         m_Texture.Apply ();
    13.  
    See the unity texture example.

    That's the reason why the performance is acceptable.:)