Skip to content

Instantly share code, notes, and snippets.

@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 / .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()

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:

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):
@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,
@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 / 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;
// clang -O3 gl-preferred-format.c -o gl-preferred-format -lGL -lglut
#include <stdio.h>
#define GL_GLEXT_PROTOTYPES
#if defined(__GNUC__) && (defined(__APPLE_CPP__) || defined(__APPLE_CC__))
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
@rdb
rdb / cg2glsl.py
Last active September 28, 2022 11:28
Convert Cg shaders designed for Panda3D to GLSL shaders. Requires cgc.exe to be installed (part of the NVIDIA Cg Toolkit)
import subprocess
import sys
import os
glsl_extensions = {'v': '.vert', 'f': '.frag', 'g': '.geom'}
if len(sys.argv) != 2:
print("Usage: cg2glsl.py something.sha")
sys.exit(1)
@rdb
rdb / example.py
Created February 22, 2015 01:02
Example GLSL shader in Panda with simple texture mapping
from panda3d.core import Shader
vshader = """#version 140
// Vertex inputs
in vec4 p3d_Vertex;
in vec2 p3d_MultiTexCoord0;
// Uniform inputs
uniform mat4 p3d_ModelViewProjectionMatrix;