Someone asked me about this possibility yesterday. So I tried it while I had some time left waiting for the 1.9 builds to finish. It surprisingly only took me a few hours to compile Panda3D to JavaScript using emscripten and create a WebGL back-end (based on our existing GLES2 back-end).
@wezu: It’s real! I’m afraid I don’t have Roaming Ralph ported (yet). I will have to compile the CPython interpreter to JavaScript for that. (There’s a sentence I never thought I’d say!)
Drag middle mouse to rotate. Also try W, to toggle between wireframe modes, or Alt+Enter to switch to full screen mode.
@stereoscopic: oh, you’re right! I didn’t even consider that. It appears to run on my Android phone as well, although touch events are not yet supported.
It’s an image of a virtual file system containing the models and textures to load. It was automatically generated by emscripten using the --preload-file option to emcc.
Here’s the C++ Hello World sample ported: rdb.name/panda3d-webgl/hello_world.html
I’ve made some performance improvements already, but there are still plenty of ways it can be optimized.
This is astonishing news. And the js.file is still small compared to js generated by other game engines. I guess thesee 7 mb is the whole Panda engine? Is there any chance of having this feature in some of the upcoming releases?
Sort of - it’s the core engine plus the new WebGL rendering back-end compiled together. Support for a lot of auxiliary features has not been compiled in, such as loading PNG or JPG files, freetype fonts, or Python bindings. Adding those is bound to increase the size, but I’m sure there are ways we can optimize (compressing the js file should help a lot already).
It’s just a little pet project for now. I’m about to commit it to a Git branch so that others can contribute. It could be added to a future version if it’s improved to the point where it’s generally useful and stable.
Add --profiling to CXXFLAGS when you want to keep the names of C++ methods in the JavaScript call stack, besides allowing you to use the Chrome profiler or something like that.
Right now it builds the C++ hello world sample and pview. Care must be taken that main_loop() is used (instead of manually stepping through do_frame) since it needs some special logic to hand control of the main loop to the browser.
This is the makefile I use to build the sample programs:
EDIT: I forgot to mention that it won’t run from file:/// URLs for security reasons. You have to use “python -m SimpleHTTPServer” and then go to localhost:8000 in your browser in order to run the resulting html.
Thanks to help of ThomasEgi, I’ve made significant progress with porting Python. Here’s the Asteroids sample program working in the browser: rdb.name/asteroids/main.html
The .js file is 24 MB uncompressed, so it may be a bit slow to download, since I don’t have gzip on the server. It’s only 4.5 MB when compressed.