This tool allows you to seamlessly mix your C++ and Python code for the Panda3D Game Engine.
It makes compiling your C++ code the matter of a single mouse-click.
- Automatic Python bindings using
interrogate
- Works on Windows, Linux and Mac
You can use the download-zip button, or clone this repository. Copy it to a suitable path in your project.
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_H
After you wrote your C++ code, run python build.py
. It will ask you for
a module name, for this example we will choose "TestModule".
When the compilation finished, there should now be a TestModule.pyd
/ TestModule.so
(depending on your platform) generated.
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
- The Panda3D SDK (get it here)
- CMake 2.6 or higher (get it here)
- windows only: The thirdparty folder installed in the Panda3D sdk folder (See here)
For compiling on Windows 32 bit:
- Visual Studio 2010/2015
For compiling on Windows 64 bit:
- Visual Studio 2010/2015
- Windows SDK 7.1 (be sure to tick the VC++ 64 bit compilers option)
Please clean up your built directories after changing the configuration! You can
do so with passing --clean
in the command line.
Command line options are:
--optimize=N
to override the optimize option. This overrides the option set in theconfig.ini
--clean
to force a clean rebuild
Further adjustments can be made in the config.ini
file:
- You can set
generate_pdb
to0
or1
to control whether a.pdb
file is generated. - You can set
optimize
to change the optimization. This has to match the--optimize=
option of your Panda3D Build. - You can set
require_lib_eigen
to1
to require the Eigen 3 library - You can set
require_lib_bullet
to1
to require the Bullet library - You can set
require_lib_freetype
to1
to require the Freetype library - You can set
verbose_igate
to1
or2
to get 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}")