Skip to content

Instantly share code, notes, and snippets.

Last active Jul 30, 2019
What would you like to do?
Custom Python loader plug-in example for Panda3D
from direct.showbase.ShowBase import ShowBase
from panda3d.core import *
# Use this import to make sure you support the VFS
from direct.stdpy.file import open
class SmurfLoader:
# Human-readable name of the format
name = "Smurf"
# Supported extensions, without leading dot.
# The primary extension should come first.
extensions = ['smurf', 'smrf']
# Set this to True if you use the methods on VirtualFileSystem with
# auto_unwrap=True to automatically unwrap .gz/.pz files.
supports_compressed = False
def load_file(path, options, record=None):
fp = open(path, 'rb')
# Any raised exception will count as a load failure
if != b'smrf':
raise RuntimeError("Not a valid smurf file!")
# Mark dependent files as you encounter them (for proper caching)
if record:
# We may return any PandaNode, but ModelRoot is best
root = ModelRoot("loaded model")
return root
# Optional; but don't define it if you don't support saving
#def save_file(path, options, node):
# open(path).write('stuff')
# To register it explicitly:
registry = LoaderFileTypeRegistry.get_global_ptr()
# To have Panda import it from an external package, put this in your metadata:
#entry_points={"panda3d.loaders": ["smurf = my_package.my_module:SmurfLoader"]}
# Happy loading!
base = ShowBase()
model = loader.loadModel('model.smurf')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment