pygame-web / pkg-porting-wasm

Tracks porting efforts on some modules you'd like to have working in pygbag
https://pygame-web.github.io/wiki/pkg/
4 stars 0 forks source link

panda3d: use --git pygbag #6

Open gabriel-v opened 1 year ago

gabriel-v commented 1 year ago

This is about the panda3d wheel included in pygbag archives.

First, I tried following the panda3d tutorial here: https://docs.panda3d.org/1.10/python/introduction/tutorial/loading-the-grassy-scenery

But it fails at self.scene = self.loader.loadModel("models/environment") - even after placing the models folder in the browser vfs, even by giving it the full path self.loader.loadModel("/path/to/models/environment.egg").

Then, I tried loading the model from memory. But the panda3d VirtualFileSystem class doesn't work:

>>> from panda3d.core import VirtualFileSystem
>>> vfs = VirtualFileSystem()
>>> vfs.makeDirectory('/ze-models')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AssertionError: result != nullptr at line 580 of panda/src/express/virtualFileSystem.cxx

same for the "global" VirtualFileSystem:

>>> from panda3d.core import VirtualFileSystem
>>> vfs = VirtualFileSystem().getGlobalPtr()
>>> vfs.makeDirectory('/ze-models')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AssertionError: result != nullptr at line 580 of panda/src/express/virtualFileSystem.cxx
pmp-p commented 1 year ago

you should use egg2bam with the embed textures option , that's the standard way of packaging for wasm or android since it the native Panda3D memory format => you need environment.bam

the egg loader has a bad history with wasm, and i'm not sure it was ever fixed. so i'll note a possible bug here. it works fine

You don't need Panda3D vfs when using pygbag since it's redundant, unless you need encryption.

pmp-p commented 9 months ago

now .egg and .bam should work both, i did not test .pz but there's a tool provided in Panda3D to unpack them.

a default model extension should be set.

see more here https://pygame-web.github.io/wiki/pkg/panda3d/

test here : https://itch.io/c/3724091/panda3d-wasm

rdb commented 9 months ago

An HTTP loader is mounted to the VFS by default, and you can't make directories on the server, so that's why makeDirectory fails.

pmp-p commented 9 months ago

indeed for file/directory write operations you want to use the normal filesystem (python I/O) which work in browser memory via emscripten MEMFS until tab is closed. For small non volatile writes the simplest way is https://pygame-web.github.io/wiki/pygbag-code/#handling-persistent-data-across-sessions