Skip to content

Instantly share code, notes, and snippets.

View rdb's full-sized avatar

rdb

View GitHub Profile
@rdb
rdb / temp.cpp
Last active January 5, 2016 17:38
Color temperature to linearized sRGB color
// Recalculate the color.
PN_stdfloat mm = 1000.0 / temperature;
PN_stdfloat mm2 = mm * mm;
PN_stdfloat mm3 = mm2 * mm;
PN_stdfloat x, y;
if (temperature < 4000) {
x = -0.2661239 * mm3 - 0.2343580 * mm2 + 0.8776956 * mm + 0.179910;
} else {
x = -3.0258469 * mm3 + 2.1070379 * mm2 + 0.2226347 * mm + 0.240390;
@rdb
rdb / custom_bam_types.py
Last active June 6, 2023 18:09
This gist demonstrates how to use the new .bam reading hooks to define custom types in Python or define a loader hook for existing types. Requires Panda 1.10.
"""
This example shows how to use the new Python factory function in the BamReader
in order to add a custom hook that is called when the BamReader encounters an
object of a certain type.
You can also use this to add a custom hook whenever the bam reader loads an
existing type, for example if you want to do some post-process task on every
GeomNode or Material loaded from the .bam file.
"""
@rdb
rdb / vertex-pulling.py
Last active April 12, 2023 19:47
Snippet demonstrating vertex pulling in Panda3D
from panda3d.core import *
#load_prc_file_data("", "gl-version 3 3")
from array import array
# Create two silly triangles.
data = array('f', [
0, 4, 0,
1, 4, 1,
0, 4, 1,
from panda3d import core, direct, physics, fx, egg
import sys
if len(sys.argv) > 1:
classname = sys.argv[1]
else:
classname = input("class> ")
for module in [core, direct, physics, fx, egg]:
if hasattr(module, classname):

Keybase proof

I hereby claim:

  • I am rdb on github.
  • I am rdb (https://keybase.io/rdb) on keybase.
  • I have a public key whose fingerprint is 2C05 2186 A18D E379 EEC5 C534 92F0 6704 80AD 5260

To claim this, I am signing this object:

@rdb
rdb / .py
Created November 12, 2017 20:16
# When importing a Panda class, importing everything into the namespace is considered bad style:
from panda3d.bullet import *
# Instead, it is better to enumerate each class specifically:
from panda3d.bullet import BulletWorld, BulletDebugNode
# This gets quite tedious to maintain, so it is easier to do:
from panda3d import bullet
w = bullet.BulletWorld()
@rdb
rdb / main.py
Created March 1, 2018 20:13
Geometry shaders with adjacency in Panda3D
from panda3d.core import *
from direct.showbase.ShowBase import ShowBase
shader = Shader.load(Shader.SL_GLSL, "silh.vert", "silh.frag", "silh.geom")
base = ShowBase()
model = base.loader.loadModel("teapot.egg")
model.reparentTo(base.render)
model.setShader(shader)
model.setRenderModeThickness(2.0)
@rdb
rdb / test.py
Last active July 30, 2019 10:50
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"
@rdb
rdb / calc-tight-bounds-xform-general.patch
Created July 9, 2019 08:55
Patch to allow Panda3D to calculate bounds in projected space
diff --git a/panda/src/gobj/geomPrimitive.cxx b/panda/src/gobj/geomPrimitive.cxx
index afa406e921..73aaf77c40 100644
--- a/panda/src/gobj/geomPrimitive.cxx
+++ b/panda/src/gobj/geomPrimitive.cxx
@@ -1612,7 +1612,7 @@ calc_tight_bounds(LPoint3 &min_point, LPoint3 &max_point,
// Find the first non-NaN vertex.
while (!found_any && i < cdata->_num_vertices) {
reader.set_row(cdata->_first_vertex + i);
- LPoint3 first_vertex = mat.xform_point(reader.get_data3());
+ LPoint3 first_vertex = mat.xform_point_general(reader.get_data3());

This is the technical documentation for the .bam format. This is generally not useful except for developers who insist on writing their own tools to manipulate .bam files without using the Panda APIs.

== Bam versions ==

The .bam format has a major.minor version scheme. The format is designed to be backward compatible, so that .bam files created with older versions of Panda3D will generally work with newer versions of Panda3D, although occasionally compatibility has been broken due to major changes in the Panda3D structures.