This tool allows you to seamlessly mix your C++ and Python code for the Panda3D Game Engine.
It generates Python bindings for your C++ code and packages the result as an installable Python wheel.
- Automatic Python bindings using
interrogate - Builds as a standard Python wheel via
pip/python -m build - Works on Windows, Linux and Mac
- Python 10 – 3.14
You can use the download-zip button, or clone this repository.
Typically it is recommended you create a new repository using this one as the template. This ensures you immediately have access to the CI workflows for automating your wheel builds and publishing to pypi.
Set module_name to the name you want for your module (e.g. TestModule).
You can also set a description.
You can now start to write your C++ code and store it in the source/ directory.
Here's a simple example you can start with (save it as source/example.h for example):
#ifndef EXAMPLE_H
#define EXAMPLE_H
#include "pandabase.h"
BEGIN_PUBLISH // This exposes all functions in this block to python
inline int multiply(int a, int b) {
return a * b;
}
END_PUBLISH
class ExampleClass {
PUBLISHED: // Exposes all functions in this scope, use instead of "public:"
inline int get_answer() {
return 42;
};
};
#endif EXAMPLE_HBuild and install directly into your environment:
pip install .Or build a distributable wheel:
pip install build
python -m build --wheelThe wheel will be placed in the dist/ directory.
Using your compiled module is straightforward:
import panda3d.core # Make sure you import this first before importing your module
import TestModule
print(TestModule.multiply(3, 4)) # prints 12
example = TestModule.ExampleClass()
print(example.get_answer()) # prints 42- Python 3.10+
- The Panda3D SDK (not the pip package — the SDK headers are needed for compilation)
- CMake 3.16 or higher
- A C++ compiler matching your Panda3D build:
| Platform | Compiler |
|---|---|
| Windows | Visual Studio 2015 – 2022 (must match the Panda3D SDK) |
| Linux | GCC / Clang |
| macOS | Xcode / Clang |
After changing the configuration, delete the build output directory so that CMake picks up the new settings on the next build.
All build options are set in config.ini:
module_name— Name of the compiled module (required).description— Short description included in the wheel metadata.optimize— Optimization level (default3). Should match the--optimize=level your Panda3D was built with.generate_pdb— Set to1to generate a.pdbdebug-info file (Windows only).require_lib_eigen— Set to1to require the Eigen 3 library.require_lib_bullet— Set to1to require the Bullet physics library.require_lib_freetype— Set to1to require the FreeType library.verbose_igate— Set to1or2for detailed interrogate output (1 = verbose, 2 = very verbose).
If you want to include additional (external) libraries, you can create a
cmake file named additional_libs.cmake in the folder of the module builder,
which will then get included during the build.
If you would like to include the protobuf library for example, your cmake file could look like this:
find_package(Protobuf REQUIRED)
include_directories(${PROTOBUF_INCLUDE_DIRS})
set(LIBRARIES "${LIBRARIES};${PROTOBUF_LIBRARIES}")
This project is licensed under the MIT License.