Skip to content

Instantly share code, notes, and snippets.

@rdb
rdb / optimizer.py
Created December 11, 2022 16:58
Collision scene optimizer for Panda3D
from panda3d.core import *
from array import array
def optimize_collisions(np, *, convert_geometry=False, ignore_z=False, preserve_name=True, preserve_tags=True, track_progress=None):
"""Organizes all "into" collision nodes below this level into an octree or
quadtree (actually an AABB tree, but never mind that) for greatly speeding
up collisions.
If convert_geometry is True, also converts all GeomNodes (unless you set
@rdb
rdb / mocap.py
Last active January 2, 2023 20:29
Motion capture animation recording in Panda3D
from panda3d.core import CharacterJoint, CharacterSlider, CharacterVertexSlider
from panda3d.core import AnimBundle, AnimGroup, AnimChannelScalarDynamic
from panda3d.core import AnimChannelMatrixXfmTable, AnimChannelScalarTable
from panda3d.core import PTA_float
class MotionCapture:
def __init__(self, actor, part_name="modelRoot", lod_name="lodRoot"):
self.part_bundle = actor.get_part_bundle(part_name, lod_name)
self.joint_tables = {}
@rdb
rdb / points.py
Created March 17, 2021 12:06
Rendering many points in Panda3D
from panda3d.core import *
from random import random
num_points = 100000
vdata = GeomVertexData('points', GeomVertexFormat.get_v3(), GeomEnums.UH_static)
vdata.set_num_rows(num_points)
vertex = GeomVertexWriter(vdata, 'vertex')
for i in range(num_points):
@rdb
rdb / async_coro.hpp
Last active March 1, 2021 11:40
Glue for using C++ coroutines with Panda3D's task system
#include <coroutine>
class AsyncCoroutineTask final : public AsyncTask {
public:
AsyncCoroutineTask() = default;
~AsyncCoroutineTask() = default;
ALLOC_DELETED_CHAIN(AsyncCoroutineTask);
virtual DoneStatus do_task() {
_done_status = DS_cont;
@rdb
rdb / client.js
Last active July 2, 2024 00:07
Minimal Node.js-based PStats server implementation (updated 2024-05-14 for PStats 3.2)
const MSGTYPE_DATAGRAM = 0;
const MSGTYPE_HELLO = 1;
const MSGTYPE_DEFINE_COLLECTORS = 2;
const MSGTYPE_DEFINE_THREADS = 3;
const MSGTYPE_EXPIRE_THREAD = 4;
/**
* Contains a single collector definition as sent by the client.
*/
class CollectorDef {
@rdb
rdb / svelte-hooks.js
Last active April 19, 2020 21:24
Patches Meteor.subscribe and Tracker.autorun to stop when a Svelte component is destroyed. Also supports await block for subscriptions.
import { current_component } from 'svelte/internal';
_autorun = Tracker.autorun;
Tracker.autorun = function autorun() {
const computation = _autorun.apply(this, arguments);
if (current_component) {
current_component.$$.on_destroy.push(computation.stop.bind(computation));
}
return computation;
};
@rdb
rdb / instancing.py
Last active February 17, 2021 13:41
InstancedNode sample (requires latest master branch)
from direct.directbase import TestStart
from panda3d.core import *
from random import random
shader = Shader.make(Shader.SL_GLSL, """
#version 150
in vec4 p3d_Vertex;
in vec4 p3d_Color;
in vec2 p3d_MultiTexCoord0;

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.

@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());
@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"