Berkelium in Ogre

A place to show off your latest screenshots and for people to comment on them. Only start a new thread here if you have some nice images to show off!
User avatar
duststorm
Minaton
Posts: 921
Joined: Sat Jul 31, 2010 6:29 pm
Location: Belgium
x 80
Contact:

Re: Berkelium in Ogre

Post by duststorm »

Yes, you can define callbacks from java.
Otherwise it would be a bit too limited to serve as, for example, a user interface.
Developer @ MakeHuman.org
Kosmos
Kobold
Posts: 29
Joined: Mon Aug 01, 2011 5:08 pm
Location: Russia

Re: Berkelium in Ogre

Post by Kosmos »

can i also pass parameters to JS code?
executeJavascript (WideString javascript) doesn't look like takes any parameters, aside of JS function name
would be good to see exactly this examples on wiki, since it the most important part of using this as GUI

I have this good example of calling JS <--> C# functions example: http://notions.okuda.ca/2009/06/11/call ... ol-from-c/
everything is so easy, i wish it were possible to do the same here, by creating ObjectForScripting thingie
User avatar
duststorm
Minaton
Posts: 921
Joined: Sat Jul 31, 2010 6:29 pm
Location: Belgium
x 80
Contact:

Re: Berkelium in Ogre

Post by duststorm »

I agree it would be interesting to write this out.
The reason I didn't is that at the moment I didn't really need communication between browser and application.

To my knowledge there are two ways to communicate from JS to C++ with berkelium.

One is by writing messages on the JS console (using the js statement "console.log()"), intercepting these in your C++ application and writing a dispatcher to invoke the correct function with the right parameters.
Much like is documented here and here.
This is a little tedious, but works.

The more direct way is implementing the onJavascriptCallback function of your windowDelegate. There you can write your dispatcher that handles the called function name and parameters.
Make sure to invoke Window::synchronousScriptReturn with the return value to javascript, or the java interpreter in your berkelium browser will hang.
I'm not 100% sure, but I think "onJavascriptCallback" is executed everytime a window.functionName() is executed where functionName was not bound to the window object (sort of like a default fallback).


And passing parameters to js calls, that's easy, just parse your parameter into a text value (this can be in the form of a literal, string or json object, anything that real javascript can understand, basically).
For example, passing an int to a javascript (this is C++ code):

Code: Select all

int value = 5;
window.executeJavaScript("functionName("+Ogre::StringConverter::toString(value)+");");
Have a look at the executeJavaScript method in the API docs.

Unfortunately calling a js function does not allow you to retrieve the return value, so any values you want to pass to C++ code will have to be communicated either through a callback to C++, or by printing the value on the console and intercepting it in your C++ app.


This sample can also be useful, however beware that "bindCallback" is an old berkelium API call that is now replaced by "onJavascriptCallback".
Last edited by duststorm on Mon Sep 03, 2012 7:06 pm, edited 4 times in total.
Developer @ MakeHuman.org
Kosmos
Kobold
Posts: 29
Joined: Mon Aug 01, 2011 5:08 pm
Location: Russia

Re: Berkelium in Ogre

Post by Kosmos »

Thank you for explaining this thing to me.
Second link solutions is looks not that bad
Last link also not that easy as c# example, but i can extract some basic ideas from there :)

Also, while you are here, i want to ask another question.
I want to use this as GUI, but as i see where it render some html pages on planes and etc, it's not transparent at all.
I wanted to set that browser window to overlay whole render window content, then i want to place different buttons and other things on that page, and i want that game itself be visible through Berkelium window, aside of places where buttons and other controls placed. How to do it? Can i set somehow page background transparent, but other controls no?

For example, if i do that page:

Code: Select all

<html>
   <head></head>
   <body>
      <table width = "100%" heigth = "100%">
         <tr><td><img src = "asd.jp" /></td></tr>
         <tr><td></td></tr>
      </table>
   </body>
</html>
I want that only asd.jpg picture were visible, while other part of page were transparent and player can use mouse to click through that page for mesh selecting and etc

Thank you again :)
User avatar
saejox
Goblin
Posts: 260
Joined: Tue Oct 25, 2011 1:07 am
x 36

Re: Berkelium in Ogre

Post by saejox »

Kosmos wrote:Is there anyway to use window.external in JavaScript code to execute C++ functions?
I can see it support this to execute JS code:
virtual void executeJavascript (WideString javascript)=0
Execute Javascript in the context of the Window.

But is there anyway to call c++ functions from JS?
not directly.
c++ catches registered javascript callbacks. then you do whatever you like with them.

in JS

Code: Select all

function CallSomeFunction(param1, param2, param3)
{
// empty
}
first register callback

Code: Select all

mWindow->bind(Berkelium::WideString::point_to("CallSomeFunction"), Berkelium::Script::Variant::bindFunction(Berkelium::WideString::point_to("CallSomeFunction"), false));


receive callback. every time CallSomeFunction if called in js you will receive this call.

Code: Select all

void onJavascriptCallback( Window *win, void* replyMsg, URLString origin, WideString funcName, Script::Variant *args, size_t numArgs )
{
 // you have function name and all parameter here. do what you want with them
 // parameter can be BOOL, NUMBER, STRING or NULL
}
Nimet - Advanced Ogre3D Mesh/dotScene Viewer
asPEEK - Remote Angelscript debugger with html interface
ogreHTML - HTML5 user interfaces in Ogre
User avatar
duststorm
Minaton
Posts: 921
Joined: Sat Jul 31, 2010 6:29 pm
Location: Belgium
x 80
Contact:

Re: Berkelium in Ogre

Post by duststorm »

Aha! Thanks for the explanation saejox. So that's the missing link. The javascriptCallback is not a default fallback, but you need to explicitly bind functions of the window (which also need to be defined, but not implemented, in javascript). Is the function body of the bound js function still executed or is it replaced with whatever you do in the callback?

Also, remember to make the window return out of a callback function, or you javascript interpreter will halt (js is single threaded in browsers).
Developer @ MakeHuman.org
User avatar
saejox
Goblin
Posts: 260
Joined: Tue Oct 25, 2011 1:07 am
x 36

Re: Berkelium in Ogre

Post by saejox »

duststorm wrote:Aha! Thanks for the explanation saejox. So that's the missing link. The javascriptCallback is not a default fallback, but you need to explicitly bind functions of the window (which also need to be defined, but not implemented, in javascript). Is the function body of the bound js function still executed or is it replaced with whatever you do in the callback?

Also, remember to make the window return out of a callback function, or you javascript interpreter will halt (js is single threaded in browsers).
i never need to do something in the bound js function.
but i believe function body will not be executed.

there is also onAlert(Window*, string) callback.
which is handy if you just want to pass a string to c++.
most of the time this is enough.

here are some of my thoughts on working with html GUI,

- best way to work with berkelium, is embracing MVC model.
- your ui should be functional just by itself in Chrome. much easier to debug.
- there are many great ui libraries for javascript. i cant think myself working without jquery, YUI is also awesome for creating tables and such.
- disable mouse selection with style='-webkit-user-select: none;' on body.
- utilize CSS3 animations. there are just great
Nimet - Advanced Ogre3D Mesh/dotScene Viewer
asPEEK - Remote Angelscript debugger with html interface
ogreHTML - HTML5 user interfaces in Ogre
User avatar
duststorm
Minaton
Posts: 921
Joined: Sat Jul 31, 2010 6:29 pm
Location: Belgium
x 80
Contact:

Re: Berkelium in Ogre

Post by duststorm »

Totally agree with your pointers.
What makes it so great for GUI development is that you can test the GUI separate from the application in a web browser like chromium or firefox. As an additional plus you get the wonderful debug features that chromium or firebug offers.
I wouldn't work without jquery either.

I'm still wondering whether you actually need to define the bound functions in js, or that it also works without. :D

All in all, this is a very powerful GUI toolkit.
Developer @ MakeHuman.org
User avatar
Marc
Gremlin
Posts: 182
Joined: Tue Jan 25, 2005 7:56 am
Location: Germany
Contact:

Re: Berkelium in Ogre

Post by Marc »

Hi !

I just tried using Berkelium with Ogre with this: http://www.ogre3d.org/tikiwiki/tiki-ind ... ntegration
It's not working for me. I can compile and run it but I see no browser window. Besides that, when I call browseToPage("http://localhost"); insted of ogre3d.org, I don't get an entry in my access.log - so Berkelium also doesn't execute the http request.

The wiki says it's been tested on 8.0.552.23 of Berkelium. I'm on Windows and according to the github page, they have completely different Version numbers for Linux and Windows. So I assume that refers to Linux. I'm trying it with the Windows build Version 11.0.696.57 .

Has anyone used this lately on a current Ogre and got it working?
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
User avatar
saejox
Goblin
Posts: 260
Joined: Tue Oct 25, 2011 1:07 am
x 36

Re: Berkelium in Ogre

Post by saejox »

i am using 11.0.696.57 on windows with ogre 1.7.
I draw on both overlay and entity. it works as expected.
Nimet - Advanced Ogre3D Mesh/dotScene Viewer
asPEEK - Remote Angelscript debugger with html interface
ogreHTML - HTML5 user interfaces in Ogre
User avatar
Marc
Gremlin
Posts: 182
Joined: Tue Jan 25, 2005 7:56 am
Location: Germany
Contact:

Re: Berkelium in Ogre

Post by Marc »

Thx for the Feedback. :) I'll investigate further than. Must be my fault somewhere ...
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Post Reply