Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity3d plugin for embedding webpages on WINDOWS is ready!

Discussion in 'Made With Unity' started by lubo3d, Mar 24, 2011.

  1. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    Ehh, no. Whenever you are using setPixels and Apply, you are not using openGL calls, it is a generic way to upload data to the graphics card and works on directX and openGL; it is really slow. We use SetPixels and Apply on the Berkelium integration, and the older Awesomium integration and they both suffer from the Achilles heel that is SetPixels() and Apply().

    OpenGL calls would consist of something like:

    Code (csharp):
    1.  
    2. extern "C"
    3. {
    4.     void updateTexture( int nTexId )
    5.     {
    6.         glBindTexture(GL_TEXTURE_2D, nTexId);
    7.         char* bytes = (char*) calloc(50 * 50, 3);
    8.         for( int i = 0 ; i < 50*50*3; i++ )
    9.         {
    10.             bytes[ i ] = 0;
    11.         }
    12.        
    13.         glTexSubImage2D(GL_TEXTURE_2D, 0, GL_RGB, 50, 50, 0,
    14.             GL_RGB, GL_UNSIGNED_BYTE, (GLvoid *)bytes);
    15.        
    16.         free( bytes );
    17.        
    18.     }
    19. }
    20. And this is how I call the function in Unity
    21. Code:
    22. [DllImport ("TestPlugin")]
    23. private static extern void updateTexture( int nTexId );
    24.  
    ...
    Code (csharp):
    1.  
    2. void Update()
    3. {
    4. m_nID = texVideo.GetInstanceID();
    5. Debug.Log( "m_nID: " + m_nID );
    6. updateTexture( m_nID + 1 );
    7. }
    8.  
     
  2. 1a2a3a

    1a2a3a

    Joined:
    Mar 27, 2011
    Posts:
    2
    can you open the links in the self-window
     
  3. lubo3d

    lubo3d

    Joined:
    Mar 23, 2011
    Posts:
    75
    Actually UnityWebCore can do it in some callback way to create new UnityWebView texture into a new plane.

    It may be an advanced usage:)
     
  4. lubo3d

    lubo3d

    Joined:
    Mar 23, 2011
    Posts:
    75
    Reissgrant,

    Really appreciate for your sample code!

    I did some benchmark in my dev desktop:

    Using SetPixels and Apply:
    Displaying normal webpage like google.com, the frame rate is 680 fps.
    Playing flash movies, the frame rate is 13 fps.

    Using glTexSubImage2D to access the graphics card directly:
    Displaying normal webpage like google.com, the frame rate is 690 fps.
    Playing flash movies, the frame rate is 280 fps.

    The frame rate significantly improved when playing flash movie!!!!!!!!!
    The only defect of using OpenGL API is that we need to force unity to run in OpenGL mode by adding optioin "-force-opengl".
    In windows platform, D3D may have rendering advantage than OpenGL. That depends on the game developers choice.

    Anyway, we have an alternative way to significantly improve the dynamic image frame rate.

    Thanks Reissgrant a lot for your recommendation!!

    PS: I'd like to correct the usage of texture id:)

    Code (csharp):
    1.  
    2. void Update()
    3. {
    4. m_nID = texVideo.GetNativeTextureID();
    5. Debug.Log( "m_nID: " + m_nID );
    6. updateTexture( m_nID);
    7. }
    8.  
    I will upload the latest version of UnityWebCore in two or three days.
    UnityWebCore will leave the two solutions coexist and developers can choose anyone.
     
  5. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    lubo3d that looks like a great increase! Nice work!
     
  6. z4g0_legacy

    z4g0_legacy

    Joined:
    Aug 13, 2010
    Posts:
    1
    @Lubo3d: Great, great plugin!!
    +1 for crossplatform version request (macosx expecially for iOS :) )
     
  7. lubo3d

    lubo3d

    Joined:
    Mar 23, 2011
    Posts:
    75
    After adding the support for rendering directly to Graphic memory in OpenGL Mode, the framerate improves significantly when playing flash videos in UnityWebCore.
    Now the framerates are ALMOST THE SAME when playing videos and showing static webpages.(1100 fps)

    See the screenshots of the comparison of framerate in the two situations.
    $flashvideo.JPG
    $googlehome.JPG

    Make sure to read the "Readme-force-opengl.txt" in both of the Demo and Project Package before playing with it.

    Demo package download.

    Project Source package download.
     
  8. skycc

    skycc

    Joined:
    Oct 1, 2010
    Posts:
    11
    there is a problem that when i open another page at google or anyother webpage,it will open the browser outside my program
     
  9. sc3

    sc3

    Joined:
    Nov 2, 2010
    Posts:
    103
    Hi lubo3d, good work so far.

    I have encountered some problems getting this working, unfortunately.

    I modified the scripts in the package so that it would open a specific address automatically, and removed the control panel GUI. It worked perfectly fine and as expected, in the Unity Editor. However when I made a build, the plane didn't show anything but its white material.

    On a different PC, I downloaded your newest demo to test if that worked. It won't seem to load the HTML nor web pages now, and it simply shows a black plane. I downloaded the newest package and again, it worked in the Unity Editor. I tried making a build from the project and when I tried to play it, I got a BSoD. Upon restarting, I tried to run the build again and got a "Failed to initialize player" error:

    $Failed to initialize error.png

    Any idea what could be causing the problem?

    Thanks
     
  10. lubo3d

    lubo3d

    Joined:
    Mar 23, 2011
    Posts:
    75
    Actually it's the default behavior in free edition. If you want to customize the behavior, you might want to get a commercial license.
     
  11. lubo3d

    lubo3d

    Joined:
    Mar 23, 2011
    Posts:
    75
    Hi, SC3

    You might want to read the "Readme-force-opengl.txt" first. Because the newest version of UnityWebCoreDemo added the performance improvement when playing flash video, it could only be run in OpenGL mode. If "force-opengl" is not used, it will only show a black plane.

    So pls run the "UnityWebCoreDemo.bat" instead of the exe file in the Demo package.

    If you made a new build after eliminating the control panel GUI, you need to load one url address manually in the C# script after creating the webview. Or you will see a white plane because no html file is loaded.

    As to the Unity errors you encountered, you can try to delete the previous built files before you building and replacing the old ones. I'm not sure about it, but you can have a try:)
     
  12. Jarhead

    Jarhead

    Joined:
    Jul 4, 2009
    Posts:
    38
    I just found this thread...sounds really awesome!

    I have one quick question. Is it possible to communicate back and forth between unity and action script in the swf? In other words, if i have an inventory management user interface written in flash is it possible for the flash UI to communicate with unity using ExternalInterface or something to that effect?
     
  13. lubo3d

    lubo3d

    Joined:
    Mar 23, 2011
    Posts:
    75
    Yes, UnityWebCore support communication between unity and AS in the swf which embedded in the webpage.
    For example, the embeded id of flash is "MyFlash".
    You can call UnityWebCore.CallJS(webviewID, "document['MyFlash'].FuncInAS", arguments) to communicate with flash from Unity.
    Before that you need to export the FuncInAS using ExternalInterface.addCallBack(...).

    Also you can call ExternalInterface.call("UnityWebCore.FuncInUnity", arguments) to communicate with Unity from ActionScript.
    Before that you need to export the FuncInUnity using UnityWebCore.AddJSCallback(...) in C#.


    UnityWebCore also supports loading swf directly! You can type one swf link into the url address box and click Go for a try.
    In that case, the id of flash object is "FlashOject".
    So you can call the function in AS using UnityWebCore.CallJS(webviewID, "document['FlashOject'].FuncInAS", arguments).

    Let us know if you have any question.
     
  14. sayezz

    sayezz

    Joined:
    Mar 9, 2011
    Posts:
    16
    just want to say that you have done a good job! fantastic!
     
  15. slgooding

    slgooding

    Joined:
    Jan 12, 2009
    Posts:
    112
    The website is down?
     
  16. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Really nice work.
    Not so much of use to me due to the force ogl which I consider inacceptable, but it is a start upon which there is a chance to see further progress and some pressure towards UT to finally allow access to the DX device and the surface so plugins can finally become meaningfull on the graphical end
     
  17. lubo3d

    lubo3d

    Joined:
    Mar 23, 2011
    Posts:
    75
    Yes, hope Unity can open the access to DX device directly just like OpenGL. That would significantly improve the performance of some graphic plugins.

    But at least if only normal webpage is used in UnityWebCore. OpenGL is not forced to use. The fps in DX mode is also acceptable.
     
  18. lubo3d

    lubo3d

    Joined:
    Mar 23, 2011
    Posts:
    75
    Yes, hope Unity can open the access to DX device directly just like OpenGL. That would significantly improve the performance of some graphic plugins.

    But at least if only normal webpage is used in UnityWebCore. OpenGL is not forced to use. The fps in DX mode is also acceptable.
     
  19. crista

    crista

    Joined:
    Mar 20, 2011
    Posts:
    5
    This is absolutely awesome! Thanks for doing this. Now if only this would work in the WebPlayer...
     
  20. FiveFingers

    FiveFingers

    Joined:
    Oct 15, 2009
    Posts:
    541
    Me vote for the OSX version :D
    Does this requires the PRO version right ?
     
  21. lubo3d

    lubo3d

    Joined:
    Mar 23, 2011
    Posts:
    75
    Yes, UnityWebCore needs PRO version because it's written in C++ plugin.
    If more developers pay $ for the win version, we can have budget for the OSX version:)
     
  22. Krodil

    Krodil

    Joined:
    Jun 30, 2010
    Posts:
    141
    just tried your system.. really nice!
    I have one question, maybe you can help.
    I have some flv/video files on my drive, which I would like to run from a local html.
    As far as I can see it is not possible to run flv's locally. True? :)
    I am really interested in avoiding playing from a server and wish a local solution.
    Do you have any pointers?
     
  23. lubo3d

    lubo3d

    Joined:
    Mar 23, 2011
    Posts:
    75
    If you want to play flv or other type of videos either from network or from local, you need a video player while the promising type is flash video player.

    There are many free flash video player or open source ones which are excellent. You can choose one and build to swf file. Put the video file(flv) beside the video player(swf), specify the video file name either in a config file or as the parameter to the swf file.

    Load the flash video player from local for example:
    html/myFlashVideoPlayer.swf?src=myVideo.flv

    You can have the video played in Unity. Just try it and let us know if you have any question.
     
    Last edited: Apr 19, 2011
  24. slgooding

    slgooding

    Joined:
    Jan 12, 2009
    Posts:
    112
    Am I going crazy? I can't access your website...
     
  25. lubo3d

    lubo3d

    Joined:
    Mar 23, 2011
    Posts:
    75
    Last edited: Apr 19, 2011
  26. Fenrisul

    Fenrisul

    Joined:
    Jan 2, 2010
    Posts:
    618
    *edit*

    Free edition... got it. sorry for lack of reading. (That was more like a foot note)
     
    Last edited: Apr 19, 2011
  27. Krodil

    Krodil

    Joined:
    Jun 30, 2010
    Posts:
    141
    SOLUTION to playing local videos through your project:
    1:Installed a WAMPserver from http://www.wampserver.com/en/download.php
    2: made a script in Notepad and afterwards saved it as 'test.html':
    Code (csharp):
    1. <html>
    2. <head>
    3.     <title>Wow! this is a header</title>
    4.    
    5. </head>
    6. <body>
    7.  
    8. <object width="550" height="400">
    9. <param name="movie" value="test.swf">
    10. <embed src="test.swf" width="550" height="400">
    11. </embed>
    12. </object>
    13.  
    14. </body>
    15. </html>
    16.  
    3: Made a folder with the script(now a html file), the test.swf file and named it 'videotest'
    4:Make sure your server is running (You dont need to do anything setting it up, use default settings ).
    5: copy your 'videotest' folder into the 'www' folder under your WAMP directory (usually C:wamp/www)

    6: Play the WebCore scene in Unity and in adress fill in: C:\wamp\www\videotest\test.html
    alternatively 'http://localhost/videotest/test.html'
    This has solved my problems in NOT storing huge video files online and NOT pre-load huge movietextures when running a scene in Unity.
    Thnx for your tool, and hope this solution adds to its use.

    Questions for the developer: I want to load different preadressed instances of the plane when interaction with different buttons has been performed? Same as spawning a movie texture, but with your system :)
     
    Last edited: Apr 19, 2011
  28. lubo3d

    lubo3d

    Joined:
    Mar 23, 2011
    Posts:
    75
    Wow!!! Really appreciated for your story which makes one feasible way to load the local movies into Unity!

    Great work, Krodil!
     
  29. thelackey3326

    thelackey3326

    Joined:
    Sep 17, 2010
    Posts:
    34
    @lubo3d: In order for me to use this, I need to return a value from Unity to Flash, as well as get a return from Flash to Unity, via the External Interface. Can this be done (or added) in UnityWebCore?

    Also, I have a SWF I use to test my existing External Interface API that is basically a textbox where you type a function name and button that executes the function. I can click in the textbox, highlight text in the textbox, delete text from the textbox using backspace, but I can't type into the textbox. Has anyone else seen this behavior?
     
    Last edited: Apr 25, 2011
  30. mehware

    mehware

    Joined:
    Nov 19, 2007
    Posts:
    739
    +1 on OSX support :D.
     
  31. clement

    clement

    Joined:
    Apr 23, 2011
    Posts:
    1
    I noticed one bug and have a solution that I would like to share with others. My project has a bunch of render textures and cameras. In OpenGL mode the plugin would overwrite one of the other render textures (in addition to updating the correct render texture). You would see the webpage in two places rather than just the intended object. It seemed to be overwriting whatever was the active camera at the time, but only if the active camera is pointing to a render texture.

    This bug is not visible in the editor... only visible in the built versions of the game in OpenGL mode.

    The solution I have to an additional "GarbageRenderTexture" that is never shown on screen and activate it before you update the UnityWebCore object.

    Put this GarbageRenderTexture.cs in the plugins folder and call it before you render into OpenGL textures using a plugin/getnativeid

    This happens in the update function in the UnityWebView.cs

    Code (csharp):
    1.  
    2.         GarbageRenderTexture.absorbBug();   // bug fix code goes right before the texture is updated
    3.         UnityWebCore.Update();  // original code
    4.  

    P.S. This fixes similar bugs in other plugins for example the QuickTime plugin or procedural texture synthesis plugins.

    View attachment $GarbageRenderTexture.cs
     
  32. lubo3d

    lubo3d

    Joined:
    Mar 23, 2011
    Posts:
    75
    Thanks clement for the sharing!!!
     
  33. Krodil

    Krodil

    Joined:
    Jun 30, 2010
    Posts:
    141
    We need something in js, I have big troubles in dissecting the code :D
     
  34. lubo3d

    lubo3d

    Joined:
    Mar 23, 2011
    Posts:
    75
    Here, I'd like to share the easiest way playing local flv video files , just like reading piece of file.
    Fill "html/videoplayer.swf" into "File" editbox and click "Load". If you want to play your own flv file, just change the config in vcastr.xml.

    The AS3 source of videoplayer.swf could be downloaded from http://vcastr.googlecode.com/svn/trunk/vcastr3/release/src.zip


    This sample is included in the latest demo package.
     
  35. Retronamic

    Retronamic

    Joined:
    Apr 28, 2011
    Posts:
    66
    This is a little unstable. Crashes when opening flash movies on Windows XP and Flash Player 10.
     
  36. lubo3d

    lubo3d

    Joined:
    Mar 23, 2011
    Posts:
    75
    Retronamic,

    UnityWebCore depends on external flash player plugin(npswf32.dll). Make sure that the flash player you are using is the latest release version.
    If you still encounter the crash problem, would you please post the screenshot or some steps that we can reproduce?

    Thanks.
     
  37. Retronamic

    Retronamic

    Joined:
    Apr 28, 2011
    Posts:
    66
    Is this Windows .exe build only? No webplayer support on Windows?
     
  38. lubo3d

    lubo3d

    Joined:
    Mar 23, 2011
    Posts:
    75
    Yes, UnityWebCore introduces Webkit engine into Unity. WebKit is developed by native C++. So there may be less possiblity to port to Unity webplayer:(
     
  39. Retronamic

    Retronamic

    Joined:
    Apr 28, 2011
    Posts:
    66
    I see. Thanks for the info, though.


    ps.: Any ETA for Webplayer support?
     
  40. lubo3d

    lubo3d

    Joined:
    Mar 23, 2011
    Posts:
    75
    Webplayer can access html or flash easily via Unity interaction with web browser. Although it's not embedded into Unity directly, it's an alternative way.

    For the security reason, webplayer doesn't support access to dll written in native C++. So maybe there won't any chance for UnityWebCore supporting webplayer unless Unity webplayer integrates this part.
     
  41. dansav

    dansav

    Joined:
    Sep 22, 2005
    Posts:
    510
    Other devices?
    iphone/ipad/android?

    How would those work.

    How does this project relate to Awesomium? and don't they want 999 dollars for their plug-in?

    Dan
     
  42. dansav

    dansav

    Joined:
    Sep 22, 2005
    Posts:
    510
    I can't get teh unitywebcoredemoproject.7z to unstuff or unzip.
    It hangs on the last file both on the pc and mac.

    Is there another demo available?

    Dan
     
  43. mehware

    mehware

    Joined:
    Nov 19, 2007
    Posts:
    739
    Can I run the paypal site securely so users can truly purchase in app?
     
  44. lubo3d

    lubo3d

    Joined:
    Mar 23, 2011
    Posts:
    75
    I tested UnityWebCore, it works well with paypal.
     
  45. mda7

    mda7

    Joined:
    Aug 18, 2010
    Posts:
    6
    +1 for MAC support.
     
  46. Krodil

    Krodil

    Joined:
    Jun 30, 2010
    Posts:
    141
    Hey Lubo, any updates?
     
    Last edited: Jul 14, 2011
  47. juampa11

    juampa11

    Joined:
    Aug 28, 2011
    Posts:
    2
    great job!
    Is there available documentation ?
    sorry for my poor English :S
     
  48. Patruno

    Patruno

    Joined:
    Sep 1, 2011
    Posts:
    1
    very impressing work, but i have a question.

    can .swf files read keyboard inputs?

    For example, i cant play a keyboard's .swf game
     
    Last edited: Sep 1, 2011
  49. SEG-Veenstra

    SEG-Veenstra

    Joined:
    Sep 3, 2010
    Posts:
    326
    It keeps amazing me what can be accomplished in this awesome program called Unity.
    And of course it keeps amazing me what certain people can accomplish!
     
  50. Jenson

    Jenson

    Joined:
    Sep 19, 2011
    Posts:
    5

    I have some problems:
    1.run UnityWebCoreDemo.bat and it's like this:
    http://hi.csdn.net/attachment/201109/19/0_1316416949nqp4.gif
    the words are unnormal and fhe fps is low

    2.run UnityWebCoreDemo.exe ,it's like this:
    http://hi.csdn.net/attachment/201109/19/0_13164170570NV1.gif
    a black plane ,but the words and the fps are normal

    3.Set the "BForce OpenGL" to false in UnityWebCoreView.cs in the project of the demo,rebuild it and run,picture is below:
    http://hi.csdn.net/attachment/201109/19/0_1316417236E2br.gif

    a black background and only has a gray

    4.In Unity Editor,no matter the BForce OpenGL is true or false, there is no effect:
    http://hi.csdn.net/attachment/201109/19/0_13164173193icy.gif

    but it has color ,not only gray


    My os is windows 7 and the Unity is not a pro version.