Panda3D WebGL Port!

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).

So, here’s pview for you to try out: (triangle) (animated panda) (FPS demo, with fancy cn04+tobspr loader)
Drag the middle mouse around to rotate as you are used to doing in pview. Preferably use Chrome - although I think certain versions of FireFox should work as well.

Live Python editor with other demos included:

Exciting, isn’t it? :slight_smile:

If you would like to build this for yourself, I’ve put together some instructions here:

1 Like

Nice! It even worked on my iPad! where can I download it?

rdb -> You need to post a Roaming Ralph WebGL demo or confess that was an april’s fool easter egg… because I’m not sure anymore :blush:

Well done!!

@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!)

If this is more convincing, here is the animated Panda model in pview:

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.

This is amazing! One question is what is the .data file you are using?

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:
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.

Pushed to webgl-port branch.

This is the build script I use to build Panda: (requires Emscripten SDK, of course)

source /home/rdb/local/src/emsdk_portable/
export CXXFLAGS="-std=c++11"
python makepanda/ --nothing --use-direct --use-gles2 --optimize 4 --outputdir embuilt --target emscripten $@

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:


PRELOAD_FILES=panda-model.bam panda-walk4.bam maps/panda-model.txo
PANDA_LIBS=libp3framework.bc libpanda.bc libpandaexpress.bc libp3dtool.bc libp3dtoolconfig.bc libp3pystub.a libp3webgldisplay.bc

CFLAGS=-O3 --profiling -s ASSERTIONS=1 -s NO_EXIT_RUNTIME=1 -s TOTAL_MEMORY=32000000

all: pview-panda.html

pview-panda.html: pview-panda.cxx $(PRELOAD_FILES)
	em++ -o pview-panda.html -L$(BUILT)/lib -L$(BUILT)/tmp pview-panda.cxx $(addprefix $(BUILT)/lib/,$(PANDA_LIBS)) -I$(BUILT)/include/ $(CFLAGS) $(addprefix --preload-file ,$(PRELOAD_FILES))

	rm -f pview-panda.html pview-panda.js pview-panda.html.mem

.PHONY: all clean

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.

trying to compile webgl but getting the error Could not find source file: p3webgldisplay_composite1.cxx

My bad, forgot to check in the webgldisplay directory. Fixed now.

dtool/src/prc/p3prc_composite2.cxx:5:10: fatal error: ‘emscriptenLogStream.cxx’
file not found

Oops, that’s another thing I forgot to commit. Pushed. Sorry about that.

I just got Python to work in the browser! Here’s the Python version of the Hello World sample running in the browser:

There’s still a lot of work to do, particularly in patching Python, though, so I haven’t checked anything in yet.

Nice! I wonder if it would be possible to add bullet physics support to panda web gl?

Thanks to help of ThomasEgi, I’ve made significant progress with porting Python. Here’s the Asteroids sample program working in the browser:

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.

Sure, I don’t see why not.

Congratulations! Thank you!

Amazing work you guys :smiley:

I would so looooove to use Panda3D and export to HTML5 :smiley:

I don’t know C++ otherwise I would try to help :cry:

If I may ask , how much work remains to be done ?

Finally can you please , please provide a write-up of how we might be able to do the very same :smiley:

I apologize if I come across as impatient , its really a very exciting thing :smiley:

Thank-you again rdb and ThomasEgi and everyone else :smiley: :smiley: