Building a Panda3d Application (OSX and linux)

Get needed tools
pythonget(recommend 3.8, have not worked with 3.9 yet)
the python version used in the last line below has to be the same as what you use here
on mac, might need to do:
pyenv install 3.8.6
pyenv global 3.8.6 [sets 3.8.6 as the default]
be sure node (windows and osx) or nodejs (linux) is installed
be sure flex is installed (pip install flex)
install panda3dpip install panda3d [need 1.10.9 or more recent]
install emscriptengetfollow platform-specific notes
get a copy of the panda3d build toolkit, specifically the webgl-port branchgit clone --branch webgl-port
download a copy of the thirdparty toolsgetwill be named webgl-editor-and-dependencies
copy the thirdparty and editor directories from this download into <panda3d-webgl-port path>/be sure the libpython in thirdparty/emscripten-libs/python/lib matches the version of python you will use
if there is an 'embuilt' directory in <panda3d-webgl-port path>, delete itthis forces a build from scratch; you need this for a new build
copy from <webgl-editor-and-dependencies path>/editor/ to your application directory
Emscripten compile panda3d
be sure flex and bison are installedcheck with bison --version, flex --version
sudo apt install flex
sudo apt install bison
cd to <panda3d-webgl-port path>
./<emsdk path>/emsdk_env.shset up emscripten environment variables might need chmod+x
Critical: be sure emscripten is in your PATH. Especially these:
<path to>/emsdk
<path to>/emsdk/upstream/emscripten
<path to>/emsdk/node/12.18.1_64bit/bin
python makepanda/ --use-png --use-jpeg --use-egg --use-zlib --use-freetype --use-bullet --no-openssl --use-direct --use-pview --use-gles2 --use-openal --use-python --use-vorbis --no-egl --target emscripten --outputdir embuilt --optimize 4 --threads 4no-png means let the browser use its own png processing. It works fine

threads argument is optional for faster build on faster machines
there will be MANY warnings, but they are ok

get lunch -- this will take a half hour or more
Emscripten compile your application
edit these lines in THIRDPARTY_DIR = /<path to>/panda3d-webgl-port/thirdparty/emscripten-libs" PY_MODULE_DIR = "/<path to>/Python-3.8.6/Modules" PY_STDLIB_DIR = "/<path to>/Python-3.8.6/lib" PANDA_BUILT_DIR = "/<path to>/panda3d-webgl-port/embuilt" PRELOAD_FILES = [<quoted comma-separated list of EVERY asset in your application with directories>]eg 'models/wall.bam',... for PRELOAD list
either rename your app starting file to or edit the freezer.addModule line to be your file
cd to your application directory
python3.8 -OO freezify.pydouble cap-O
if you get an out of memory error in the JavaScript console, modify TOTAL_MEMORY= in
########## # # get a list of all files in asset directories suitable for cut/paste # into PRELOAD_FILES # # walks subdirectories # ########## import os assetList = "" ASSET_DIR = "<path to your application>" # edit this to list all top-level asset directories dirs = ["models","pics","audio","images","floors"] def stripDir(sdir,dire): dirloc = sdir.find(dire) return sdir[dirloc:] for dire in dirs: fnum = 0 for subdir, dirs, files in os.walk(ASSET_DIR+dire): for file in files: if file[0]!=".": if fnum<1: assetList+= '"'+stripDir(subdir,dire)+'/'+file+'"' else: assetList+= ',"'+stripDir(subdir,dire)+'/'+file+'"' fnum+=1 print (assetList)