Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Berkelium plugin: rendering interactive websites

Discussion in 'Made With Unity' started by JeDi, Jul 6, 2010.

  1. JeDi

    JeDi

    Joined:
    Jun 16, 2010
    Posts:
    52
    Hi all,

    Berkelium is a wrapper around Google Chromium, and provides a way to render and interact with browser windows. I am creating a Unity plugin around this, so we can have also have interactive websites inside a Unity environment, in Windows (Mac users can use the htmlTexture plugin. I may sync my script API to match with that plugin once it is finished).

    Note that I had to use native code for this plugin, so this is Unity Pro only for now, and it can't be used inside a browser.


    You can find my first attempt at this plugin at http://research.edm.uhasselt.be/~nve/OSMA/UnityBerkeliumPlugin.zip

    The plugin still only has basic functionality, but I am actively working on it as we speak. This release is just proof that I am actually getting some results Wink

    The zip-file contains Berkelium, the source code and vs2008 solution of the plugin, a Unity test project and a test release so people without Unity Pro can see it working.


    Next things on my list is implementing support for scrolling, and caching the dirty rectangles to support partial updates using SetPixels (see reissgrant's comment above). After that, I will have a look at binding keyboard input.

    All contributions and comments are more than welcome of course!

    And a screenshot:



    Greetz,
    JeDi
     
  2. liverolA

    liverolA

    Joined:
    Feb 10, 2009
    Posts:
    347
    sweet,keep it up!
     
  3. DjOscar527

    DjOscar527

    Joined:
    Nov 15, 2009
    Posts:
    800
    So basically you can not only load the websites, but interact with them as well?
    e.g. I load website on a plane, run the app and it will allow me to navigate through the website which is on a plane, click links etc?

    if its that then sweet :)
     
  4. JeDi

    JeDi

    Joined:
    Jun 16, 2010
    Posts:
    52
    Yep, that's exactly what it does. You can render and interact with basically everything that Google Chrome can render. I have to investigate this a bit (I have no experience with neither Unity nor Berkelium), but I guess this can also be used as a GUI texture (using transparent websites). And it is just a texture, so you can use it on other objects than planes too (in-game terminals for example).

    Mind that the current implementation is not efficient yet, and scolling doesn't work properly. But those features are almost finished, and then it will be pretty efficient.
     
  5. JeDi

    JeDi

    Joined:
    Jun 16, 2010
    Posts:
    52
    I updated the plugin (same download link). These are the changes:
    - Fly around with the right mouse button pressed (very simple fly script)
    - Interaction can be enabled/disabled per object
     
  6. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    Awesome job. Think using a shader to do the BGRA to RGBA swap instead of doing it in the loop would save many cycles? Probably not many as you have to loop through the whole thing to convert it to a float anyways, but might help a little bit.
     
  7. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    Use a float lookup table instead of calculating the conversion to float, it will save some time:

    Code (csharp):
    1. static const float lookup[]=
    2. {
    3.          0.0f,  0.00392157f,  0.00784314f,   0.0117647f,   0.0156863f,   0.0196078f,   0.0235294f,    0.027451f,
    4.    0.0313726f,   0.0352941f,   0.0392157f,   0.0431373f,   0.0470588f,   0.0509804f,    0.054902f,   0.0588235f,
    5.    0.0627451f,   0.0666667f,   0.0705882f,   0.0745098f,   0.0784314f,   0.0823529f,   0.0862745f,   0.0901961f,
    6.    0.0941177f,   0.0980392f,    0.101961f,    0.105882f,    0.109804f,    0.113725f,    0.117647f,    0.121569f,
    7.      0.12549f,    0.129412f,    0.133333f,    0.137255f,    0.141176f,    0.145098f,     0.14902f,    0.152941f,
    8.     0.156863f,    0.160784f,    0.164706f,    0.168627f,    0.172549f,    0.176471f,    0.180392f,    0.184314f,
    9.     0.188235f,    0.192157f,    0.196078f,         0.2f,    0.203922f,    0.207843f,    0.211765f,    0.215686f,
    10.     0.219608f,    0.223529f,    0.227451f,    0.231373f,    0.235294f,    0.239216f,    0.243137f,    0.247059f,
    11.      0.25098f,    0.254902f,    0.258824f,    0.262745f,    0.266667f,    0.270588f,     0.27451f,    0.278431f,
    12.     0.282353f,    0.286275f,    0.290196f,    0.294118f,    0.298039f,    0.301961f,    0.305882f,    0.309804f,
    13.     0.313726f,    0.317647f,    0.321569f,     0.32549f,    0.329412f,    0.333333f,    0.337255f,    0.341176f,
    14.     0.345098f,     0.34902f,    0.352941f,    0.356863f,    0.360784f,    0.364706f,    0.368627f,    0.372549f,
    15.     0.376471f,    0.380392f,    0.384314f,    0.388235f,    0.392157f,    0.396078f,         0.4f,    0.403922f,
    16.     0.407843f,    0.411765f,    0.415686f,    0.419608f,    0.423529f,    0.427451f,    0.431373f,    0.435294f,
    17.     0.439216f,    0.443137f,    0.447059f,     0.45098f,    0.454902f,    0.458824f,    0.462745f,    0.466667f,
    18.     0.470588f,     0.47451f,    0.478431f,    0.482353f,    0.486275f,    0.490196f,    0.494118f,    0.498039f,
    19.     0.501961f,    0.505882f,    0.509804f,    0.513726f,    0.517647f,    0.521569f,     0.52549f,    0.529412f,
    20.     0.533333f,    0.537255f,    0.541176f,    0.545098f,     0.54902f,    0.552941f,    0.556863f,    0.560784f,
    21.     0.564706f,    0.568627f,    0.572549f,    0.576471f,    0.580392f,    0.584314f,    0.588235f,    0.592157f,
    22.     0.596078f,         0.6f,    0.603922f,    0.607843f,    0.611765f,    0.615686f,    0.619608f,    0.623529f,
    23.     0.627451f,    0.631373f,    0.635294f,    0.639216f,    0.643137f,    0.647059f,     0.65098f,    0.654902f,
    24.     0.658824f,    0.662745f,    0.666667f,    0.670588f,     0.67451f,    0.678431f,    0.682353f,    0.686275f,
    25.     0.690196f,    0.694118f,    0.698039f,    0.701961f,    0.705882f,    0.709804f,    0.713726f,    0.717647f,
    26.     0.721569f,     0.72549f,    0.729412f,    0.733333f,    0.737255f,    0.741176f,    0.745098f,     0.74902f,
    27.     0.752941f,    0.756863f,    0.760784f,    0.764706f,    0.768628f,    0.772549f,    0.776471f,    0.780392f,
    28.     0.784314f,    0.788235f,    0.792157f,    0.796079f,         0.8f,    0.803922f,    0.807843f,    0.811765f,
    29.     0.815686f,    0.819608f,    0.823529f,    0.827451f,    0.831373f,    0.835294f,    0.839216f,    0.843137f,
    30.     0.847059f,     0.85098f,    0.854902f,    0.858824f,    0.862745f,    0.866667f,    0.870588f,     0.87451f,
    31.     0.878431f,    0.882353f,    0.886275f,    0.890196f,    0.894118f,    0.898039f,    0.901961f,    0.905882f,
    32.     0.909804f,    0.913726f,    0.917647f,    0.921569f,     0.92549f,    0.929412f,    0.933333f,    0.937255f,
    33.     0.941177f,    0.945098f,     0.94902f,    0.952941f,    0.956863f,    0.960784f,    0.964706f,    0.968628f,
    34.     0.972549f,    0.976471f,    0.980392f,    0.984314f,    0.988235f,    0.992157f,    0.996078f,         1.0f,
    35. };
    To use it, call:
    Code (csharp):
    1.  
    2.                  for (int x = 0; x < *pRectW; x++)
    3.                 {
    4.                     floatpixel[0] = lookup[bytepixel[2]];
    5.                     floatpixel[1] = lookup[bytepixel[1]];
    6.                     floatpixel[2] = lookup[bytepixel[0]];
    7.                     floatpixel[3] = 1.0f; // A
    8.                     floatpixel+=4;
    9.                     bytepixel+=4;
    10.                 }
    11.  
     
  8. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    Ok, in case you need it, here is my entire update rect function for updating the dirty rect and converting to RGBA using the lookup table (for Awesomium, but think it is similar enough to help):
    Code (csharp):
    1. void UpdateTextureInPluginRect(float* colors_rect)
    2. {
    3.     if (webCore!=NULL)
    4.     {
    5.         webCore->update();
    6.          if(webView->isDirty())
    7.          {
    8.             webView->render(buffer_rect, W4, 4, &rect);
    9.            
    10.             *pDirty = true;
    11.             *pRectX = rect.x;
    12.             *pRectY = rect.y;
    13.             *pRectW = rect.width;
    14.             *pRectH = rect.height;
    15.             *pRectBool = rect.isEmpty();
    16.  
    17.             floatpixel = colors_rect;
    18.                  
    19.             for (int y = 0; y < *pRectH; y++)
    20.             {
    21.                  if(*pRectY < 2 )
    22.                  {
    23.                      *pRectOffset = (((( *pRectY + y ) * WIDTH) + *pRectX)*4);
    24.                      
    25.                  }
    26.                  else
    27.                  {
    28.                      *pRectOffset = (((((*pRectY - 1) + y + 1) * WIDTH) + *pRectX)*4);
    29.                  }
    30.                 bytepixel = buffer_rect + *pRectOffset;
    31.  
    32.                
    33.                  for (int x = 0; x < *pRectW; x++)
    34.                 {
    35.                     floatpixel[0] = lookup[bytepixel[2]];
    36.                     floatpixel[1] = lookup[bytepixel[1]];
    37.                     floatpixel[2] = lookup[bytepixel[0]];
    38.                     floatpixel[3] = 1.0f; // A
    39.                     floatpixel+=4;
    40.                     bytepixel+=4;
    41.                 }
    42.             }
    43.         } else {*pDirty = false;}
    44.     }
    45. }
     
  9. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    Here is my C# keyboard injection code (modified code from solmyr) This mimics a native windows key event:
    Code (csharp):
    1. void keyHandler()
    2. {
    3.     if (flashHit ==true) // does Flash window have focus?
    4.     {
    5.         if(Input.inputString!="")
    6.         {
    7.             c = Input.inputString[0];
    8.             bs = Input.inputString;
    9.             injectKeyboard(0x0102, c);
    10.             if (bs == "\b")
    11.             {
    12.                 injectKeyboard(0x0100, (char)0x08);  // backspace
    13.             }
    14.         }
    15.     }
    16. }
     
  10. zergmouse

    zergmouse

    Joined:
    Jun 30, 2010
    Posts:
    216
    very cool stuff. On a similar note, I am still wanting to see the ability to do desktop sharing or application sharing. Like teleplace. Basically it would be nice to have an open office plugin for unity.

    I love the concept of using interactive textures. This goes so far beyond just websites. I wonder if I can make something in silverlight and render it via this plugin on a object.
     
  11. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    Probably not. While plugins should be able to be supported in the future, right now only Flash is supported by Berkelium.
     
  12. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,332
    Is there a plan to hand in-website events back to unity handling code?
    Making it possible to use html to build UI sounds interesting (at least for me and in theory).

    Cool work!
     
  13. GeneralGrant

    GeneralGrant

    Joined:
    Jun 10, 2010
    Posts:
    977
    I think I found a new ad system....


    MWU HA HA HA HAA.
     
  14. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    Yes, that is the intent, communication through javascript to Flash and back to Unity. I have a working prototype using Awesomium that does this, using Flash as my main menu and in game HUD system with transparency; but unfortunately Awesomium requires a license. This however, does not!
     
  15. JeDi

    JeDi

    Joined:
    Jun 16, 2010
    Posts:
    52
    @reissgrant Thanks for the info. I will have a look at using the tables, but first I have to implement using dirty rectangles in Unity, which will boost performance a whole lot more. Because I don't have any experience with .Net though, I am having trouble returning an array of structs from my C code back to .NET. I was hoping to do something like this in C#:
    Code (csharp):
    1.  
    2. struct Rect
    3. {
    4.   int top, left;
    5.   int width, height;
    6. }
    7.  
    8. [DllImport ("UnityBerkeliumPlugin")]
    9. private static extern Rect[] Berkelium_Window_getUpdates(int windowID);
    10.  
    but I have no idea how to bind that to C code. I am reading up on C# and marshalling, but if anyone can give me some hints, that would be greatly apprectiated.
    Note that I have a struct in C++ which has the same members (4 ints), and I hold a std::vector of those in my class, so I just have to get that vector into C# somehow...

    @TobiasS As far as I know, callbacks aren't implemented in Berkelium yet, but they are definitely on their TODO list. Awesomium does have them, but as reissgrant said, Awesomium isn't free and/or open. For GUIs this is a necessary part of the plugin, but it could be useful for a whole bunch of other things too.
    You can however call javascript functions (also with result) from Berkelium, so you can poll values for now.
     
  16. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    Unfortunately my knowledge in C# is limited too, so I resigned to returning a simple int for each one of my rect values (returnRectX(), returnRectY(), returnRectHeight() etc.) It's not pretty, but it works!
     
  17. JeDi

    JeDi

    Joined:
    Jun 16, 2010
    Posts:
    52
    Yes, I will do it like that for now too.

    On another note, I am trying to figure out keyboard injection. Could you elaborate on your code a couple of posts back please? Thanks!
     
  18. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    Code (csharp):
    1. injectKeyboard(0x0102, c);
    In the above code, 0x0102 is the WM_CHAR event (which is passed as an int) and c is the keycode (which is passed as a char).


    We'll need to pass the event and the vk_code to Berkelium for the keyEvent Function:
    Code (csharp):
    1.  
    2. virtual void Berkelium::Window::keyEvent(
    3.     bool    pressed,
    4.     int     mods, // not sure yet
    5.     int     vk_code, <--- put our "c" here (cast it to int)
    6.     int     scancode <--- put our "int" event here  
    7.    )
    8. -------------------------------------
    9. Parameters:
    10.        pressed  <---  if true indicates the key was pressed, if false indicates it was released
    11.        mods  <--- a modifier code created by a logical or of KeyModifiers
    12.        vk_code   <--- the virtual key code received from the OS
    13.        scancode   <--- the original scancode that generated the event
    Let me know if you need more :D
     
  19. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    Don't think I've mentioned this yet, but great work getting this working! :D

    I downloaded your code to help and noticed a few things so far (All in the C# script):
    Code (csharp):
    1.         m_Texture = new Texture2D (width, height, TextureFormat.ARGB32, false);
    Should be TextureFormat.RGB24 instead, slight performance boost ;)

    Add this to counteract the reverse orientation of the texture (had the same issue in Awesomium):
    Code (csharp):
    1. renderer.material.mainTextureScale = new Vector2 (1,-1);
    Also, you might want to add at the top, to be safe:
    Code (csharp):
    1.  
    2. using System.Collections;
    3.  

    *EDIT TextureScale modified to display correctly(1,-1)
     
  20. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    I was aiming to get the keyboard portion done tonight but am stuck now, because I'm getting a crash related to the mousemove() function. JeDi, are you getting the same crash or is it just me?
     
  21. JeDi

    JeDi

    Joined:
    Jun 16, 2010
    Posts:
    52
    I got a crash sometimes, but I didn't notice it was due to a mousemove event. I thought it was a threading issue or something. Do you know if Berkelium calls the delegate from the main thread or not?

    Sorry for the delayed answers. I am moving to a new house and I don't have an internet connection yet. I will be working on this again full throttle on Monday.

    We can make transparency optional, because it can be useful for GUIs and such (using transparent sites).
     
  22. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    No problem JeDi, I hope moving goes well for you ;). I'm still trying to pin down the crash source. I don't know what thread the delegate is called from.

    *EDIT
    Ok the crash is happening somewhere in the Berk::update() function according to my error logs, always before or after the onPaint(), but ONLY when mousemove is enabled and at random times after that. Confused yet? :D I'll try to look at it more tomorrow.
     
  23. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    Ok I found what was causing the crashes, I was missing a dll in my Unity exe directory.

    Also, text input is done!~

     
  24. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    You guys kick ass! What's left to do?
     
  25. gamesurgeon

    gamesurgeon

    Joined:
    Oct 11, 2009
    Posts:
    427
    This could literally revolutionize indie gaming with awesome integrated ads.

    You rule.
     
  26. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,603
    the question is what ads cause most ad providers do not allow you to use them on standalone and will terminate your ad account immediately etc (google adsense etc all do not allow this)
     
  27. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    Thanks!

    Left to do:
    1.) Rect rendering (only render portion that needs updating)*in progress
    2.) Transparency
    3.) Javascript calls
    4.) ???
     
  28. GeneralGrant

    GeneralGrant

    Joined:
    Jun 10, 2010
    Posts:
    977
    5.) PROFIT!
     
  29. agentdm

    agentdm

    Joined:
    Jun 16, 2010
    Posts:
    1
    wchar conversion is pretty rudimentary but this works for inputting javascript.

    Code (csharp):
    1.  
    2. PLUGIN_API void Berkelium_Window_executeJavascript(int windowID, char* javaScript, int scriptLength )
    3. {
    4.    
    5.     cerr << "Javascript call made: " << javaScript << endl;
    6.     UnityBerkeliumWindow *pWindow = getWindow(windowID);
    7.  
    8.    
    9.     // Convert to Wchar ( is there an easier way to do this? )
    10.     const int strlength = 100;
    11.     wchar_t wctStrJScript[strlength];
    12.     MultiByteToWideChar( CP_ACP, 0, javaScript, scriptLength,
    13.                          wctStrJScript, strlength );
    14.     wctStrJScript[scriptLength] = 0;
    15.  
    16.     cerr << "Javascript converted: " << caStrJScript << endl;
    17.     if(pWindow)
    18.         pWindow->getBerkeliumWindow()->executeJavascript(wctStrJScript, scriptLength);
    19.     else
    20.         cerr << "Warning: no berkelium window found with ID " << windowID << "!" << endl;
    21. }
    22.  
     
  30. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    agentdm, awesome! Thanks for the help. It may be rudimentary but as long as it works, it is useful :D

    Rect rendering is *mostly* working (still one or two bugs to work out)

    I think the framerate is acceptable:
    *disclaimer: this framerate is only when the texture is not updating
     
  31. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    Yeah, but that's a static page. What happens when you have big dirty rects being continually generated? Try playing a youtube video. But excellent work so far, I'm really looking forward to this.
     
  32. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    Obviously the framerate will drop with the rect constantly updating, but with a youtube movie playing, you'll get around 120 fps (depends on the rect size) as opposed to 25fps with the whole page updating. But realistically, you shouldn't be using this texture to display movies, that's what the movietexture is for. Ideally you would use this for a flash (or html) interface which only updates when buttons are clicked, not for something where the whole screen is animating at once.

    As a note, the framerate could be even further improved if Unity provided a way to access textures directly using directx functions. Maybe that will change in 3.0??? hint hint!!
     
  33. liverolA

    liverolA

    Joined:
    Feb 10, 2009
    Posts:
    347
    how is everything?
     
  34. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    Rect rendering is done. Now I'm working on transparency. I'm also working on loading local files.

    For some reason:
    Code (csharp):
    1. file:///C:/htmlTest/test.html
    does not work, so we may have to get involved in the API and write some code for loading a local file.

    I'll upload what I have so far so everyone can test it.
    Follow the instructions in the first post if you're having problems installing.
     

    Attached Files:

  35. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    Transparency working and casting shadows:
     
  36. jouz

    jouz

    Joined:
    May 1, 2010
    Posts:
    22
    This is really great! What are the chances to ever see such a thing running in the browser?

    What are the chances of running an instance of unity in unity? :D
     
  37. solmyr-fr

    solmyr-fr

    Joined:
    Jun 18, 2009
    Posts:
    20
    Well done reissgrant ! You've accomplished a very good work since we talked.

    For the local file problem, it's strange... I remember it worked for me (... I'm not sure... it was a year ago ^^)
     
  38. JeDi

    JeDi

    Joined:
    Jun 16, 2010
    Posts:
    52
    Wow, I had to do three days without an internet connection. I arrive at work, and practically all the work I had planned for today is done :)

    This proofs how helpful a great community can be, and that's exactly what we wanted to do with our research project. Thanks a lot guys!

    I will setup a github account or something, so it will be easier to cooperate on the code. I never did that before, so if anyone has a better solution, please share!

    Again, thanks for everyone that contributed. I'm sure this will become a valuable plugin for a lot of people. If anyone feels like creating a demo scene, with a GUI, an interactive billboard and something like this (and maybe there are even more uses for this plugin), please go ahead ;)

    I am downloading the latest attached plugin now, I will merge it with the changes I already had (if they are still useful), and upload it to github.

    Greetz,
    JeDi

    EditI noticed that no source code is attached in the latest versions. I know this is released under a "do whatever you like with it" sort of license, but could you please share the latest version of the code? Of course all authors will be credited for their work.
     
  39. JeDi

    JeDi

    Joined:
    Jun 16, 2010
    Posts:
    52
  40. liverolA

    liverolA

    Joined:
    Feb 10, 2009
    Posts:
    347
    so far,so good
     
  41. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    JeDi, Please don't misunderstand, I am going to upload my source code tonight after work. I just uploaded the plugin and dll strictly for user testing; I should have said that first.

    Some things that still need to be worked out are:
    Scrolling rect
    Receive callbacks from javascript (new function in Berk beta build for this)

    And surprisingly, local file now works. Using the same format that I posted, it works, although if you build with the latest Flash html presets the process can hang for a bit and that's what I was seeing. It's recommended to use a barebones implementation with Flash, just the embed tag and no browser checking code.

    Solmyr, Merci beaucoup!
     
  42. JeDi

    JeDi

    Joined:
    Jun 16, 2010
    Posts:
    52
    reissgrant, do you remember how you did the optional transparency? Or did you just enable transparency in berkelium? I updated the code so you can optionally enable transparency, but I am having trouble updating the texture when transparency is disabled.

    I had some trouble with this before, because when using TextureFormat.ARGB32, the color buffer actually is RGBA. I was hoping that when choosing TextureFormat.RGB24, it would just be RGB...

    I am going to implement scrolling now, because I don't think anyone is working on that yet. I also have to take a look at a cursor implementation, because now you can't really see when an input box has focus.

    Again, thanks a lot for your contributions!
     
  43. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    No problem, JeDi, thanks for starting this up!

    About the transparency, it does not work correctly, or at least, like Awesomium did. What I did was use a hack. Basically, I use a key color (in this case white) to be flagged as transparent. This can be made to be changed to a user selectable color in Unity (hot pink, green screen etc). The Berkelium setTransparency function does not work correctly, because whenever it is set to true it overrides all alpha values with one value, making the entire texture transparent. My implementation does not even set Berkelium to use transparency using this function, it just sets the alpha in the texture and Unity picks it up if ARGB is used.

    *EDIT I do not reorder the pixels based on transprency, the only difference is the texture format used (RGB, ARGB) and the scaling (1,1) and (1,-1) for the Unity material.
     
  44. JeDi

    JeDi

    Joined:
    Jun 16, 2010
    Posts:
    52
    I will fiddle around to get true transparency working. But the color key option can be very handy too. If possible, we will support both options.

    I added a function to call javascript. I changed the code a little bit from agentdm's post, so we can just use a string in the Unity script.

    Edit: I also added texture scaling so we don't have to apply a negative scale to the 3D object. Mind that I didn't update the binary files yet, because there is stuff in it for testing transparency and key input, and I can't partially commit those.
     
  45. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    JeDi, I remoted home to get my project file. I'm making some minor adjustments then I'll upload it to Github.
     
  46. JeDi

    JeDi

    Joined:
    Jun 16, 2010
    Posts:
    52
    Thanks, I am waiting impatiently ;)

    Does anyone have an idea how to properly share the binaries and Unity project for this? Unity compiles and caches a lot (in the Library directory). Is the Library directory really necessary? Maybe it gets created by Unity automatically? If so, we can omit it from the repository.

    Basically, I want to split source code and compiled binaries, so users (as opposed to developers) of this plugin can easily get the latest version to try and test.

    Edit: I read up on external versioning control support in Unity, enabled it and removed the unnecessary files from the repository
     
  47. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
  48. JeDi

    JeDi

    Joined:
    Jun 16, 2010
    Posts:
    52
    Thanks, I'll try to merge the changes as soon as possible (possibly in a couple of hours, but I am at home right now).
     
  49. JeDi

    JeDi

    Joined:
    Jun 16, 2010
    Posts:
    52
    An update of the work done the last couple of days:
    - Keyboard input works (only normal characters, backspace and return for now). Keyboard input into flash doesn't seem to work, but I'm afraid that is a Berkelium issue.
    - Transparent websites work. reissgrant also implemented a color-key solution, but I still have to merge those changes.

    Scrolling almost works, that's next on my TODO list.
     
  50. ccross20

    ccross20

    Joined:
    Jul 12, 2010
    Posts:
    5
    This is a really cool project that I'm watching closely. My company does elearning and a lot of times you have to interact with computer touch screens and this would make that possible. Just one question, is there any way to communicate with the page that you've loaded in the plugin? I've figured out the flash <-> unity communication when they're both in the browser, but this is a different animal.

    Awesome work so far, I upgraded to the Pro trial just to test it out.

    - Carter
     
unityunity