Converting from Blender — Panda3D Manual (2024)

Currently, there are several ways to get models from Blender into Panda3D. Themost popular has always been the YABEE exporter, but it is no longer recommendedas it is not compatible with the latest version of Blender, 2.80. Instead, werecommend the use of blend2bam, or to export to theglTF format.

Please note that some of these tools rely on features that were introduced inPanda3D 1.10.8, so please make sure you are using the latest stable version ofPanda3D.

  • Option 1: blend2bam

  • Option 2: Exporting to glTF

  • Option 3: Exporting to Egg

  • Material Set-Up

  • PBR Rendering

  • Why do my colors look different in Panda3D?

Option 1: blend2bam

Blend2bam is a command-line utility that converts .blend files into .bam files,which can be directly loaded into Panda3D. It does not do the conversion on itsown, but interfaces with other exporters and converters (which may differdepending on your version of Blender) and sets them up with the right settingsto get the correct result in Panda3D. It also adds a few extensions on top ofthe glTF conversion to add support for collision shapes. As such, it isconsidered the most fool-proof option for getting Blender models into Panda3D.

You can simply add this to your Panda3D installation using pip:

python -m pip install -U panda3d-blend2bam

To convert a model, enter the blend2bam command on the command-line:

blend2bam myfile.blend myfile.bam

For more information, and issue reports, visit the GitHub page for blend2bam:

https://github.com/Moguri/blend2bam

Option 2: Exporting to glTF

When using Blender 2.80 or higher, blend2bam uses the built-in glTF 2.0 exporterprovided with Blender to produce a glTF file, and then usesa Python module called panda3d-gltfto convert the model to Panda3D.

The advantage of using blend2bam is that it will automatically set up the glTFexporter and supervise this process to produce the best results for Panda3D.However, if you prefer, it is still possible to manually export the glTF filefrom Blender and load it into Panda3D.

The glTF exporter interface can be opened by going to File > Export > glTF 2.0:

The exporter interface provides many settings that can be customized, but thesettings indicated in the image above provide a good starting point. Afterdialing in the settings and selecting the file path, click “Export glTF 2.0” toproduce the glTF file.

Once you have the .gltf (or .glb) file, follow the instructions onthis page to load the model into Panda3D.

Option 3: Exporting to Egg

There is a community-provided Blender add-on called YABEE, which adds an optionto the Blender GUI for exporting Egg Files. This is considered the mostmature and stable add-on for Blender, however, it only works with Blender 2.5x,2.6x and 2.7x. It does not work with newer versions, and as such is no longerrecommended.

If you are using one of these older versions of Blender, however, this plug-inmay still be useful to you:

https://github.com/09th/YABEE

Caution

There are some community-made ports of YABEE for newer versions of Blenderfloating around the internet. These ports are not officially supported asthey are often tailored to the author’s own purposes and may not produce theexpected output in the general case.

Material Set-Up

Blender 2.80 (and higher) uses a node graph to define materials. This is a veryflexible way to define materials, but export formats are very rigid in how theylike their materials to be structured. Therefore, the exporter contains code torecognize particular combinations of material nodes and map them to themore rigidly-defined material slots of the export format.

This does mean that your materials need to be structured in a certain way inorder for them to be converted correctly. For example, you must use thePrincipled BSDF shader node in your materials, and connect its output directlyto the Surface input of the Material Output node. More information on thelimitations of the Blender exporter can be found in the Blender manual (thoughnote that not all features mentioned here are supported by Panda3D):

https://docs.blender.org/manual/en/latest/addons/import_export/scene_gltf2.html

PBR Rendering

Blender 2.80 and above use a physically-based rendering model to rendermaterials. As of this time of writing, Panda3D’s shader generator does notimplement such a rendering model. If you wish to get a rendering result thatapproaches the way the model appears in Blender, you need to use a shader thatapplies lighting in a similar way to Blender.

For best reproduction of the Blender materials, you can use the simplepbrpackage, which provides a set of shaders that are designed to approximate thePrincipled BSDF shading model used in Blender:

https://github.com/Moguri/panda3d-simplepbr

Why do my colors look different in Panda3D?

It is important to note that Blender uses a linear workflow, meaning all colorssampled from textures are converted from the sRGB gamma encoding to the“linearized sRGB” color space before being used for lighting and blending.After the render process, the colors in the framebuffer are converted back togamma-encoded sRGB for display on the screen. This results in more naturallighting and blending, because these calculations happen in a linear domain.For more reading about this topic, seethis article from “GPU Gems”.

By default, blend2bam and panda3d-gltf enable the gamma-correction feature ontextures by setting their format to Texture::F_srgb orTexture::F_srgb_alpha, but the second step of converting the colorsback to sRGB at the end of the rendering process needs to be explicitly enabledin the application. If this is not done, the texture colors will look incorrect.

If you use the panda3d-simplepbr package, this step is enabled automatically.Otherwise, you will need to configure Panda3D to enable sRGB gamma correction.This can be done by asking the graphics driver for an “sRGB framebuffer”, whichcauses the GPU to automatically convert colors back to sRGB before they aredisplayed on the monitor. This is achieved by enabling framebuffer-srgb truein Config.prc, or by adding a post-processing filter as described inCommon Image Filters.

If you do not want to use the linearized workflow, despite its benefits, you cantell blend2bam not to mark the textures as being sRGB-encoded, meaning that theyare read without gamma correction. To do this, use the --no-srgb flag.

If you do wish to use the linearized workflow, but have other models or texturesthat you wish to integrate into the same application, it is important to settheir texture to use the sRGB format as well so that they do not appear toobright. This can be done with the following code:

for tex in model.find_all_textures(): if tex.num_components == 4: tex.set_format(Texture.F_srgb_alpha) else: tex.set_format(Texture.F_srgb)
Converting from Blender — Panda3D Manual (2024)
Top Articles
Latest Posts
Article information

Author: Velia Krajcik

Last Updated:

Views: 6808

Rating: 4.3 / 5 (54 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Velia Krajcik

Birthday: 1996-07-27

Address: 520 Balistreri Mount, South Armand, OR 60528

Phone: +466880739437

Job: Future Retail Associate

Hobby: Polo, Scouting, Worldbuilding, Cosplaying, Photography, Rowing, Nordic skating

Introduction: My name is Velia Krajcik, I am a handsome, clean, lucky, gleaming, magnificent, proud, glorious person who loves writing and wants to share my knowledge and understanding with you.