Building a Distributable with GLTF Support

I’m currently trying to build a distributable version of a project that includes models in the GLTF format. In the IDE, such models are loaded without problem. However, in the distributable version the loading of them fails, producing an error message in the log of the following form:

:loader(error): Extension of file <file-path>.gltf is unrecognized; cannot load.
Currently known scene file types are:
  Bam                             .bam
:loader(error): Couldn't load file <file-path>.gltf: all matching files on model path invalid (the model path is currently: <model-path>)

The fact that the error only lists “bam” as a known file-type seems to suggest that GLTF support hasn’t been included in the build.

Conversely, however, I do have “panda3d-gltf” in my “requirements.txt” file.

Does anyone know what I’m missing? :/

At least in the case of building my Arena FPS Sample Program, which includes both .bam and .gltf models, the bdist process has no errors and produces a working executable.

Here’s my setup.py for that:

from setuptools import setup

setup(
    name='demo',
    options={
        'build_apps': {
            'gui_apps': {
                'demo': 'arena.py',
            },
            'log_filename': '$USER_APPDATA/demo/output.log',
            'log_append': False,

            'include_patterns': [
                '**/*.png',
                '**/*.bam',
                '**/*.txt',
                '**/*.prc',
                '**/*.config',
                '**/*.md',
                '**/*.otf',
                '**/*.ttf',
                '**/*.wav',
                '**/*.ogg',
                '**/*.vert',
                '**/*.frag',
                '**/*.gltf',
            ],

            'plugins': [
                'pandagl',
                'p3openal_audio',
            ],
        }
    }
)

The requirements.txt is just:

panda3d
panda3d-gltf

I happen to know what project you are likely referring to :slight_smile: so I will give a shot at building it a bit later.

Hmm… Very strange! :/

Thank you! That would be appreciated! :slight_smile:

I’ve now committed a few changes that I’ve made since last you saw the project, I believe, so it might be worth updating on your end before you attempt a build.

I’ve continued our discussion in a PM, though for everybody else who might be watching this thread, I did get the project in question to build with .gltf files in a working executable.

I’m not sure what the problem in the original post was, however, I’ll defer to somebody else on that.

I think the problem is that you need to specify the default extension in the auto configuration file setup .BAM, or vice versa, you need to check.

I should perhaps clarify: The project does build and even run on my end–but the distributable version produces the errors shown in the first post when run, where the source version does not.

Surely Panda is capable of loading files from two different extensions…? o_0

Or will it still load bam/egg.pz files if the default is set to “gltf”, but then allow the loading of the latter…?

I really don’t think that you should ship panda3d-gltf and the .gltf files with your game; rather you should register an extension handler to convert them to .bam files upon running build_apps, similar to what happens when you pack an .egg file.

@Moguri perhaps we should look for a way for panda3d-gltf to automatically register such a handler with build_apps?

Ah, I see–fair enough.

Do we have a handler that will do that?

(I’m not really familiar with the use of GLTF files, I’m afraid.)

A handler is just a Python function, it can do anything you like.

Also see Feature suggestion: Have The Build System Use "loader.loadModel" · Issue #714 · panda3d/panda3d · GitHub

Okay, fair. Do we then have a tool/function that will convert GLTF files to bam files, and that might be called by a handler?

Heh, indeed–and I’m the one who opened that issue, I believe!

Still, it doesn’t appear to have an immediate answer, that I see…

I believe gltf2bam is already a CLI tool that is part of GitHub - Moguri/panda3d-gltf: glTF utilities for Panda3D so I imagine that would just need to be tied into the native build system.

1 Like

Ah, thank you–I wasn’t aware of that!

As it happens, behind the scenes the GLTF files in question have been converted to bam files for me, so I no longer require support for the former in my build. Nevertheless, thank you all for your help here, and perhaps this will prove useful to others in the future! :slight_smile:

1 Like

I know this a bit old, but I haven’t been able to load GLTF or GLB with Panda at all. I have been using this guy’s tool: GitHub - Moguri/panda3d-gltf: glTF utilities for Panda3D to convert them to bam (I am not affiliated with that repo). It seems to work well for me so far… All of my models were originally glb, but converted to bam with gltf2bam. And I have built executables on Ubuntu and Windows 11 without any issues.

One other good thing is that gltf2bam works with a venv too as long as the venv is activated… on both Windows and Ubuntu I do not follow the typical install directions that are given in Panda3d documentation. I just treat it like any other python lib and install it into a virtualenv. I have not had any issues so far. Although I did have to apt install the recommended libs on Ubuntu… Windows worked right off the bat (odd lol).

1 Like