Torque 3D Embedded Browser (WebKit)
by Josh Engebretson · in Torque 3D Professional · 01/15/2010 (8:55 pm) · 305 replies
Hey guys,
Here are some highlights:
1) It uses QtWebKit which is based off Apple's WebKit, the same HTML5/Canvas based web rendering engine from Chrome, Safari, Adobe AIR
2) QtWebKit is *easily* the best designed embeddable web browser I have found in exhaustive travels... (I actually compiled Chrome from source at one point, not recommended). Qt is *extremely* well supported and owned by Nokia who recently paid $153,000,000 for it. So, it is probably going to be around for some time.
3) Flash works :)
4) It is setup as a GuiControl so interacts perfectly with mouse events, control overlap, filters...
There are currently 3 rendering modes:

1) Render to Texture: This mode renders the web view to an offscreen buffer and then uploads it to a GFXTexHandle. It uses the Torque GUI system input for mouse and keyboard. As we're rendering to a texture, compositing and rendering to 3d surfaces is possible. Flash renders as long as it is set to windowless mode in the HTML (not a big deal). Instead of using Flash for anything other than presentation/video playback, I would suggest looking into Canvas/HTML5/CSS animations/effects in this mode.

2) Render Native: This mode integrates a native child window with Gui Control, giving the best of both worlds :) There is no need to render to texture as we're using an actual clipped child HWND which uses the Torque GUI system for position/extents and focus :) Transparency does not currently work, however under Vista/Win7 this should be possible. I should be able to get masking working with minimal effort, which would allow for shaped windows and transparent areas.

3) Render Popup: This mode pops up a standalone window, which is owned by the application and consistent in scripting with other modes. This is useful for things like integrated document browsing, tutorial video watching, game doc reading, game forum reading, etc... where you don't want to crowd your game interface with browser. However, you want CLOSE scripted integration with a standard browser (no worries of IE/Mozilla/Chrome), which isn't possible with the current "launch browser" functionality.
These modes work with HTTPS adding a nice way to authenticate to servers, secure purchasing, etc.
It is still pretty early in the development and the idea with the code release will be to get feedback on usability and features... especially WRT integration with Javascript on the page, etc.
EDIT: The first version has been released and is available HERE
Regards,
- Josh Engebretson
Mythos Labs, LLC
Here are some highlights:
1) It uses QtWebKit which is based off Apple's WebKit, the same HTML5/Canvas based web rendering engine from Chrome, Safari, Adobe AIR
2) QtWebKit is *easily* the best designed embeddable web browser I have found in exhaustive travels... (I actually compiled Chrome from source at one point, not recommended). Qt is *extremely* well supported and owned by Nokia who recently paid $153,000,000 for it. So, it is probably going to be around for some time.
3) Flash works :)
4) It is setup as a GuiControl so interacts perfectly with mouse events, control overlap, filters...
There are currently 3 rendering modes:

1) Render to Texture: This mode renders the web view to an offscreen buffer and then uploads it to a GFXTexHandle. It uses the Torque GUI system input for mouse and keyboard. As we're rendering to a texture, compositing and rendering to 3d surfaces is possible. Flash renders as long as it is set to windowless mode in the HTML (not a big deal). Instead of using Flash for anything other than presentation/video playback, I would suggest looking into Canvas/HTML5/CSS animations/effects in this mode.

2) Render Native: This mode integrates a native child window with Gui Control, giving the best of both worlds :) There is no need to render to texture as we're using an actual clipped child HWND which uses the Torque GUI system for position/extents and focus :) Transparency does not currently work, however under Vista/Win7 this should be possible. I should be able to get masking working with minimal effort, which would allow for shaped windows and transparent areas.

3) Render Popup: This mode pops up a standalone window, which is owned by the application and consistent in scripting with other modes. This is useful for things like integrated document browsing, tutorial video watching, game doc reading, game forum reading, etc... where you don't want to crowd your game interface with browser. However, you want CLOSE scripted integration with a standard browser (no worries of IE/Mozilla/Chrome), which isn't possible with the current "launch browser" functionality.
These modes work with HTTPS adding a nice way to authenticate to servers, secure purchasing, etc.
It is still pretty early in the development and the idea with the code release will be to get feedback on usability and features... especially WRT integration with Javascript on the page, etc.
EDIT: The first version has been released and is available HERE
Regards,
- Josh Engebretson
Mythos Labs, LLC
About the author
http://www.TheEngine.Co
#162
What a riot.
02/18/2011 (12:04 pm)
Anyone have any luck popping off a GuiWebCtrl that is playing a looping Flash? When I pop the dialog the Flash sound keeps playing. I call delete on the Ctrl that removes it so it can be reinstantiated just fine, but the looping Flash audio begins to layer on the previous ones that still persist. What a riot.
#163
In the MyGameTSCtrl class, there are mouse event functions that deal with the interaction of clicking the websites on the textures.
02/18/2011 (2:36 pm)
@Brian: You need to look at the MyGameTSCtrl class in the source code that came with the original webkit download. In the MyGameTSCtrl class, there are mouse event functions that deal with the interaction of clicking the websites on the textures.
#164
02/18/2011 (2:40 pm)
@Brian: I know you got it to work because you have the latest Firefox install, but you could have also downloaded and installed the Adobe Flashplayer for "Other browsers" from adobe.com.
#165
Kind of a long post, forgive me, just trying to talk this out:
Afx uses its own Playgui, overriding the standard one, and uses its own afxTSCtrl class instead of GameTSCtrl. The afxTSCtrl enables all the Afx functionality where we can click the buttons on our ship with the left button, the two button mouse combination does the firing, holding right mouse pans, etc. This is all done through the afxTSctrl playgui that covers the whole screen.
So, normally to get webkit working we would replace the standard GameTSCtrl() with MyGameTSCtrl. If I do this in my case, it replaces afxTSCTrl with MyGameTSCtrl. See where this is going?
Basically, If I do that, the sites work on the cubes and I can click them and navigate them. Works great, love it. However, then all the stuff that worked under the afxTSCtrl - anything clickable on the ship, the mouse button configuration, etc - is no longer available.
If I in turn set the playgui back to use an afxTSCtrl, then the websites come up beautifully but cannot be navigated so the pages are stuck at that one URL. Likewise, without being able to click I can't start flash video clips. And videos do not seem to autostart.
I have been working on re-routing the chain so I can grab all the functionality from all the necessary places without affecting AFX. Kind of trying this right now:
- afxTSCtrl is used for the playgui to preserve AFX functionality.
- afxTSCtrl was inheriting from GameTSCtrl, I changed it to MyGameTSCtrl.
- MyGameTSCtrl should inherit from GameTSCtrl (instead of GuiTSCtrl - as suggested by Justin in post #71 here).
This I hoped should complete the chain.
This compiles OK and when I load the game I have all my AFX movement and clickability. Good. I then go to try a webcube. Site is there, looks great, I try to click some links.
Thing is, everything gets trapped by afxTSCtrl and the mouse inputs are not getting through to MyGameTSCtrl. I put a parent::onmousedown command in the afxTSCtrl (also following Justin's note), and echo to the console, and can see then when clicking a web link indeed it is getting to MyGameTSCtrl::onmousedown. But the link kind of seems to go active like it was clicked, but nothing happens.
So I'm once again very close but must be missing something. Perhaps the order of inheritance.
Anyhow, thanks for your thoughts on this one... I really like this kit and will keep at it until it works.
02/18/2011 (9:19 pm)
@Philip: Yes am on the track looking at that and other classes. Am kind of stuck in a chicken-before-the-egg situation though...Kind of a long post, forgive me, just trying to talk this out:
Afx uses its own Playgui, overriding the standard one, and uses its own afxTSCtrl class instead of GameTSCtrl. The afxTSCtrl enables all the Afx functionality where we can click the buttons on our ship with the left button, the two button mouse combination does the firing, holding right mouse pans, etc. This is all done through the afxTSctrl playgui that covers the whole screen.
So, normally to get webkit working we would replace the standard GameTSCtrl() with MyGameTSCtrl. If I do this in my case, it replaces afxTSCTrl with MyGameTSCtrl. See where this is going?
Basically, If I do that, the sites work on the cubes and I can click them and navigate them. Works great, love it. However, then all the stuff that worked under the afxTSCtrl - anything clickable on the ship, the mouse button configuration, etc - is no longer available.
If I in turn set the playgui back to use an afxTSCtrl, then the websites come up beautifully but cannot be navigated so the pages are stuck at that one URL. Likewise, without being able to click I can't start flash video clips. And videos do not seem to autostart.
I have been working on re-routing the chain so I can grab all the functionality from all the necessary places without affecting AFX. Kind of trying this right now:
- afxTSCtrl is used for the playgui to preserve AFX functionality.
- afxTSCtrl was inheriting from GameTSCtrl, I changed it to MyGameTSCtrl.
- MyGameTSCtrl should inherit from GameTSCtrl (instead of GuiTSCtrl - as suggested by Justin in post #71 here).
This I hoped should complete the chain.
This compiles OK and when I load the game I have all my AFX movement and clickability. Good. I then go to try a webcube. Site is there, looks great, I try to click some links.
Thing is, everything gets trapped by afxTSCtrl and the mouse inputs are not getting through to MyGameTSCtrl. I put a parent::onmousedown command in the afxTSCtrl (also following Justin's note), and echo to the console, and can see then when clicking a web link indeed it is getting to MyGameTSCtrl::onmousedown. But the link kind of seems to go active like it was clicked, but nothing happens.
So I'm once again very close but must be missing something. Perhaps the order of inheritance.
Anyhow, thanks for your thoughts on this one... I really like this kit and will keep at it until it works.
#166
Just had to put in a call to onmouseup as well, so the complete click is transmitted up through the afxtsctrl to the mygametsctrl.
Anyhow, web browsing and all the standard clickable items in the ship are all working together now perfectly.
The only thing I noticed is that I am unable to enter text on web forms or search fields, etc. I can click the field and it gets focus, but of course whatever I try to type is caught by the main playgui and interpreted as gameplay commands. So I can't type on the web yet. Anybody have any ideas?
Other than that I'm loving it, see drive-in pic below.
02/19/2011 (1:44 pm)
Got it!Just had to put in a call to onmouseup as well, so the complete click is transmitted up through the afxtsctrl to the mygametsctrl.
Anyhow, web browsing and all the standard clickable items in the ship are all working together now perfectly.
The only thing I noticed is that I am unable to enter text on web forms or search fields, etc. I can click the field and it gets focus, but of course whatever I try to type is caught by the main playgui and interpreted as gameplay commands. So I can't type on the web yet. Anybody have any ideas?
Other than that I'm loving it, see drive-in pic below.
#167
Anyone know why this thread has disappeared?
Anyhow, hopefully by posting now it will wake it up and put it back in the list.
Still wondering if anyone has an idea how to get text input working on web pages when rendering to texture. When using render native the input works great of course, because the GUI control is in front with full focus. But when rendering to texture the playgui seems to trap the keyboard commands. Getting the clicking to pass from one layer to another was easy enough, but not sure how to handle this text input issue.
Looking for any advice...
If anyone needs help getting this all working with 1.1B3 and AFX 2.0 just let me know and I can provide a full list of steps involved.
Thanks again, great resource.
02/22/2011 (6:59 am)
This thread seems to not be showing up anymore in the Torque 3D (Private) forum list. I can only get to it through the original blog post where there is a direct link to the thread.Anyone know why this thread has disappeared?
Anyhow, hopefully by posting now it will wake it up and put it back in the list.
Still wondering if anyone has an idea how to get text input working on web pages when rendering to texture. When using render native the input works great of course, because the GUI control is in front with full focus. But when rendering to texture the playgui seems to trap the keyboard commands. Getting the clicking to pass from one layer to another was easy enough, but not sure how to handle this text input issue.
Looking for any advice...
If anyone needs help getting this all working with 1.1B3 and AFX 2.0 just let me know and I can provide a full list of steps involved.
Thanks again, great resource.
#168
@Brian: I'm at the point where any help you can provide would be greatly appreciated. Apparently beating my head against the wall is not a help editing source.
02/22/2011 (8:48 am)
I too would like to obtain that functionality.@Brian: I'm at the point where any help you can provide would be greatly appreciated. Apparently beating my head against the wall is not a help editing source.
#169
After messing around with compiling the resource I bit the bullet and went straight to integration. I actually found it easier to just go right to using my own codebase.
So here are the steps to add to an existing Torque game:
Create modified QT webkit files
- Download QT webkit source
- Make a few changes
- Compile to create new set of LIBs and DLLs
Re-create Visual Studio projects and solution
- Replace your project.conf with the one in the resource, edit to match your QT path
- Run "generateprojects.bat" to create a updated Visual Studio 2008 projects and solution
- Load the solution and add back in any special source files you used in previous compiles that were not picked up by the project generator (if you keep everything within Engine you are probably fine)
Modify source to enable the QT webkit
- Follow Philip's list of steps (do Konrad's modifications, then Philip's modifications, then whatever else he lists)
- If you use AFX, do a couple more steps which I can list if you need them
Anyhow, let me know how far along you are. If you are stuck at the QT stage, I can maybe just post my modified LIB and DLL files for you to use rather than you having to compile them yourself. From there you can jump right to the Torque source. If you are using 1.1B3 and follow Philip and Konrad's steps, as well as anything else you read here, it should work. If you are getting specific errors when compiling Torque, list them here and we'll work through them.
Cheers
02/22/2011 (12:27 pm)
@Lee: Sure no problem... How far are you in the process?After messing around with compiling the resource I bit the bullet and went straight to integration. I actually found it easier to just go right to using my own codebase.
So here are the steps to add to an existing Torque game:
Create modified QT webkit files
- Download QT webkit source
- Make a few changes
- Compile to create new set of LIBs and DLLs
Re-create Visual Studio projects and solution
- Replace your project.conf with the one in the resource, edit to match your QT path
- Run "generateprojects.bat" to create a updated Visual Studio 2008 projects and solution
- Load the solution and add back in any special source files you used in previous compiles that were not picked up by the project generator (if you keep everything within Engine you are probably fine)
Modify source to enable the QT webkit
- Follow Philip's list of steps (do Konrad's modifications, then Philip's modifications, then whatever else he lists)
- If you use AFX, do a couple more steps which I can list if you need them
Anyhow, let me know how far along you are. If you are stuck at the QT stage, I can maybe just post my modified LIB and DLL files for you to use rather than you having to compile them yourself. From there you can jump right to the Torque source. If you are using 1.1B3 and follow Philip and Konrad's steps, as well as anything else you read here, it should work. If you are getting specific errors when compiling Torque, list them here and we'll work through them.
Cheers
#170
Thanks,
Lee
02/22/2011 (8:35 pm)
@Brian: I'll get back to you Monday with a status. I'm going to delouse the computer I've been using for more than T3D. Just slid a new machine into the rack and will move all the 3D modeling, animation, graphics, and audio processing software to that one and just have T3D,VS2008, AFX 2.0, and a few other really necessary things left on the original. Thanks,
Lee
#171
02/23/2011 (6:14 am)
@Lee: I am away next week but will be back online around March 7th. See how far you can get in the meantime. If you cannot get the QT to compile properly, as I said I can send you my modified LIB and DLL files so you can focus on the Torque end of things. Just let me know.
#172
Are there specific steps in terms of exporting the model, in order to enable the render to texture of the browser? As it stands when we create a new object (such as a flat control panel), then label one of the surfaces, and then try to attach a material to that surface, nothing seems to show up at all.
Your webcubes are great, however are not ideal for converting to control panel screens - as they need to be rotated on all axes into position and then scaled into a flat shape. We would love to be able to create new shapes to stick the web gui to, and also be able to do the same with existing shapes in our game.
Can you please provide any special instructions as to required software and procedures? We have Milkshape and Ultimate Unwrap, is that sufficient to create the objects in the proper format?
Thanks
02/24/2011 (7:06 am)
@Josh: Am now at the stage of trying to create my own web-enabled objects, and for some reason am having issues getting the web gui to attach to the object.Are there specific steps in terms of exporting the model, in order to enable the render to texture of the browser? As it stands when we create a new object (such as a flat control panel), then label one of the surfaces, and then try to attach a material to that surface, nothing seems to show up at all.
Your webcubes are great, however are not ideal for converting to control panel screens - as they need to be rotated on all axes into position and then scaled into a flat shape. We would love to be able to create new shapes to stick the web gui to, and also be able to do the same with existing shapes in our game.
Can you please provide any special instructions as to required software and procedures? We have Milkshape and Ultimate Unwrap, is that sufficient to create the objects in the proper format?
Thanks
#173
If I set everything up using a text editor like Torsion and stay out of the material editor GUI, I can pop any of my existing DTS models into the ship and stick any web page I want to it.
My problem was failing to edit one particular field in the GUIWebCtrl singleton - the "TargetName" has to match the name of its singleton, missed that.
Excellent!
02/24/2011 (9:53 am)
OK, got it... Just the material editor having a mind of its own.If I set everything up using a text editor like Torsion and stay out of the material editor GUI, I can pop any of my existing DTS models into the ship and stick any web page I want to it.
My problem was failing to edit one particular field in the GUIWebCtrl singleton - the "TargetName" has to match the name of its singleton, missed that.
Excellent!
#174
but I am having problem with text input entry into a Flash container now. I can query Google with text entries, and everything else that is non-Flash.
Anyone else with the issues?
02/25/2011 (8:45 am)
@Brian -- Have you resolved your text input issues yet? Apparently it will have problem out of the box with textinput into HTML forms unless I modified bool GuiWebCtrl::onKeyDown(const GuiEvent &event) to bool GuiWebCtrl::onKeyDown(const GuiEvent &event)
{
if (!isActive())
return false;
// // Wouldn't handle keys before.. now it does -- MBL
GuiWebCore::get()->viewKeyDown(mWebViewId, 0, Qt::NoModifier, event.ascii ? QString(QChar(event.ascii)) : "");
return true;
}but I am having problem with text input entry into a Flash container now. I can query Google with text entries, and everything else that is non-Flash.
Anyone else with the issues?
#175
The original onKeyDown() should be modified because Torque is somehow nulling out the event.keyCode for regular ASCII characters (pretty much anything renderable). This modification converts the ascii value over to the keyCode.
Thanks Tim R. for pointing us in the right direction.
02/25/2011 (11:07 am)
Ok-- I fixed this now and it works correctly.The original onKeyDown() should be modified because Torque is somehow nulling out the event.keyCode for regular ASCII characters (pretty much anything renderable). This modification converts the ascii value over to the keyCode.
Thanks Tim R. for pointing us in the right direction.
bool GuiWebCtrl::onKeyDown(const GuiEvent &event)
{
if (!isActive())
return false;
U16 keyCode;
if (!event.keyCode)
keyCode = Input::getKeyCode(event.ascii);
else
keyCode = event.keyCode;
S32 key;
U16 ascii;
if (event.modifier & SI_SHIFT)
ascii = Input::getAscii( keyCode, STATE_UPPER );
else
ascii = Input::getAscii( keyCode, STATE_LOWER );
if (!GuiWebCore::get()->translateKey(keyCode, key) && !ascii)
return false;
Qt::KeyboardModifiers mod = Qt::NoModifier;
if (event.modifier & SI_CTRL)
mod |= Qt::ControlModifier;
if (event.modifier & SI_SHIFT)
mod |= Qt::ShiftModifier;
if (event.modifier & SI_ALT)
mod |= Qt::AltModifier;
GuiWebCore::get()->viewKeyDown(mWebViewId, key, mod, ascii ? QString(QChar(ascii)) : "");
return true;
}
#176
Would be awesome for people who have downloaded our game demo to be flying the shuttle out in space and fly up to a feedback form and leave comments for us. Can't wait to try it out.
Not concerned about the Flash input, would be great of course but being able to fill out a web form or log into a web site is enough for us for now.
But please post the resolution for the Flash if you figure it out. Would be great to have everything working.
Cheers
02/25/2011 (11:42 am)
@Michael: No we had not resolved the issues yet, but looks like we can now :) Many thanks, will give that a try. Would be awesome for people who have downloaded our game demo to be flying the shuttle out in space and fly up to a feedback form and leave comments for us. Can't wait to try it out.
Not concerned about the Flash input, would be great of course but being able to fill out a web form or log into a web site is enough for us for now.
But please post the resolution for the Flash if you figure it out. Would be great to have everything working.
Cheers
#177
@Brian: Posted a comment at your blog.
Can someone please update the kit with all the fixes for 1.1 - Beta 3?
This kit is the main reason I bought the source for around 1000$ (grab it for 99$ while you can...), I am not sure I will be able to build it by myself...
02/25/2011 (9:13 pm)
@Michael: What a clever solution:-)@Brian: Posted a comment at your blog.
Can someone please update the kit with all the fixes for 1.1 - Beta 3?
This kit is the main reason I bought the source for around 1000$ (grab it for 99$ while you can...), I am not sure I will be able to build it by myself...
#178
Trying to get it to work here too, but the linker Error
"zlib.lib(inflate.obj) : error LNK2005: _inflateInit2_ already defined in QtCore4.lib(QtCore4.dll)"
wont go away. There is no QtCore4.dll anywhere on the system (removed them all), and still it appears. Folks here have encountered it too and seemingly surived it, so, any tipps what to look for?
02/26/2011 (8:12 pm)
Hey there, nice work so far!Trying to get it to work here too, but the linker Error
"zlib.lib(inflate.obj) : error LNK2005: _inflateInit2_ already defined in QtCore4.lib(QtCore4.dll)"
wont go away. There is no QtCore4.dll anywhere on the system (removed them all), and still it appears. Folks here have encountered it too and seemingly surived it, so, any tipps what to look for?
#179
02/27/2011 (1:10 pm)
Try zlib.lib and QtCore4.lib source files and look for _inflateInit2_
#180
02/27/2011 (6:11 pm)
Rerun GenerateProjects. Not sure if this will help.
Torque Owner Brian M
Gambit Realm
So I'm trying to trace things through and make the necessary adjustments to the code.
Anyone here gotten this running under AFX?