Skip to content

Instantly share code, notes, and snippets.

View ecmjohnson's full-sized avatar

Erik ecmjohnson

View GitHub Profile
@ecmjohnson
ecmjohnson / pid.hpp
Created November 4, 2023 16:42
Single header PID controller implementation
#pragma once
template<typename T>
class PID {
public:
PID(T Kp, T Ki, T Kd, T minInt, T maxInt) {
_kp = Kp;
_ki = Ki;
_kd = Kd;
@ecmjohnson
ecmjohnson / fix.py
Last active October 15, 2021 13:23
Utility for batch modifying images
import sys, os
import numpy as np
import imageio
from absl import app, flags
from tqdm import tqdm
opts = flags.FLAGS
flags.DEFINE_string('input_dir', 'masks', 'Input directory')
flags.DEFINE_string('output_dir', 'results', 'Outut directory')
@ecmjohnson
ecmjohnson / plywriter.py
Last active November 8, 2021 16:12
Writer for .ply geometry files (pointclouds, meshes, lines)
import traceback
"""
A simple writer for .ply geometry files. Very useful for debugging!
Buffers the contents and writes out only on exit (necessary for writing
the header without knowing the vertex/edge/face count in advance).
Closes the fd in the case a with block raises an exception.
We could wait until the exit to even open the fd; however, I decided
against that to match expected behaviour. This could accomodate a
design where the vertex/edge/face count is provided in advance.
@ecmjohnson
ecmjohnson / souptracer.py
Created July 26, 2021 12:46
Python ray-tracer for a triangle soup
import numpy as np
import numba as nb
"""
A small ray-tracer for rendering a triangle soup. It gives all intersections
along the ray (in no particular order) and does not do back-face culling.
Uses a BVH for algorithmic acceleration and numba for low-level optimization.
Usage:
```
@ecmjohnson
ecmjohnson / zoom.bat
Last active July 20, 2021 12:09
Translation of nerdyrodent/VQGAN-CLIP/zoom.sh to Windows Batch Scripting
@echo off
:: needed to modify variables in a for loop
SETLOCAL ENABLEDELAYEDEXPANSION
:: command line options
SET TEXT=%~1
SET FILENAME=%~2
SET MAX_EPOCHS=%~3
:: hardcoded options
@ecmjohnson
ecmjohnson / ObjectPool.cs
Last active June 8, 2021 12:19
Unity object pooling script
/**
* This class implements the object pool pattern:
*
* It can be used for creating objects exactly as if using Unity's `Instantiate` call. Simply
* call `AcquireObject` with a prefab and an instance of that object will be returned, either
* recycled from the pool or allocated if the pool is empty.
*
* It is the responsibility of the object to set itself inactive with `SetActive(false)` at
* lifetime end. This is how objects are recycled by the pool.
*
@ecmjohnson
ecmjohnson / nerf_blender_data_exporter.py
Last active September 13, 2022 02:11
Blender Add-on: Export animation renders using bmild/NeRF's Blender data format
bl_info = {
"name": "NeRF Data Exporter",
"description": "Outputs images and camera parameters in bmild/NeRF's Blender data format.",
"author": "ecmjohnson",
"version": (0, 3),
"blender": (2, 80, 0),
"support": "TESTING",
"category": "Import-Export",
}
@ecmjohnson
ecmjohnson / dae_obj.py
Last active May 20, 2021 10:17 — forked from PierrickKoch/dae_obj.py
Batch convert Collada to Wavefront (.dae to .obj) using Blender
"""
Batch convert Collada to Wavefront (.dae to .obj) using Blender
usage: blender -b -P dae_obj.py -- ./in_dir/ ./out_dir/
"""
import sys
import os
import bpy # Blender Python API
def clear():
""" Clears the scene """