Skip to content

Instantly share code, notes, and snippets.

View jmpinit's full-sized avatar

Owen Trueblood jmpinit

View GitHub Profile
@jmpinit
jmpinit / to_plyb.py
Created July 14, 2024 19:24
Convert a 3D file to binary PLY format with assimp and the Python plyfile package.
#!/usr/bin/env python3
import os
import subprocess
import sys
import tempfile
from plyfile import PlyData
def convert_to_ply(input_file):
@jmpinit
jmpinit / urdf_to_rigged_fbx.md
Created March 24, 2024 16:43
How to cleanly convert a URDF for a robot into a rigged FBX file (for visualization) using Blender (tested with version 3.6.5). The model can then be cleanly imported and animated in UE5, Three.js, etc.
  1. Import with the Phobos add-on
  2. Delete everything except the armatures and the visual meshes
  3. Edit the Blender file (upper right - Display Mode -> Blender File) and delete the Phobos bone visuals under Meshes
  4. Clear the parents (keep transformation) for the visual meshes
  5. Clear the armature parents
  6. Rename each bone to match the name of the parent armature so you can tell which is which after the next step
  7. Join all of the armatures
  8. In edit mode, reparent the bones in the correct hierarchy (keep offset)
  9. In object mode, parent the meshes to their corresponding bones. NOTE: Use “bone” parent not “bone relative”. If it causes an offset in the mesh then undo and repeat it again. This is probably a bug in Blender? But it works.
  10. In pose mode, move bones and confirm that the meshes move as expected.
@jmpinit
jmpinit / visit_once_by_edges.py
Created March 10, 2024 19:13
Visit all Houdini points while trying to only follow edges in the input geometry. For Houdini Python node.
import numpy as np
from python_tsp.heuristics import solve_tsp_simulated_annealing
node = hou.pwd()
geo = node.geometry()
def construct_distance_matrix(edges):
# Find the maximum index to determine the size of the matrix
max_index = max(max(edge) for edge in edges)
@jmpinit
jmpinit / blender_extract_positions.py
Created December 16, 2023 14:48
Extract the positions and orientations of specified objects in a Blender scene as JSON
# Usage:
# blender my_scene.blend --background --python extract_positions.py -- Foo Bar
import bpy
import json
import sys
def get_object_data(object_names):
data = {}
@jmpinit
jmpinit / index.html
Last active November 6, 2023 01:38 — forked from bellbind/index.html
[chrome][android] BarcodeDetector example
<!doctype html>
<html>
<head>
<script type="module">
// WICG Shape Detection API
// - https://wicg.github.io/shape-detection-api/
try {
const start = document.getElementById("start");
const video = document.getElementById("video");
const result = document.getElementById("result");
@jmpinit
jmpinit / capture.py
Created July 20, 2023 16:31
Roundabout way to get video frames from Python into the browser via FFmpeg and WebRTC.
# To test with FFmpeg only:
# python3 capture.py | ffmpeg -f rawvideo -pixel_format bgr24 -video_size 640x480 -framerate 30 -i - foo.avi
# To create WebRTC stream with [ffmpeg-to-webrtc](https://github.com/ashellunts/ffmpeg-to-webrtc):
# go run . -rtbufsize 100M -f rawvideo -pixel_format bgr24 -video_size 640x480 -framerate 30 -i video -c:v libx264 -bsf:v h264_mp4toannexb -b:v 2M -max_delay 0 -bf 0 -f h264 - < SDP.txt
import time
import cv2, sys
cam = cv2.VideoCapture(0)
@jmpinit
jmpinit / copy_material_index.py
Created May 24, 2023 15:00
Copy the `material_index` attribute between identical meshes in Blender. Makes it possible to copy per-face material assignments between meshes.
import bpy
# Get the active object
active_obj = bpy.context.active_object
# Get all selected objects
selected_objs = bpy.context.selected_objects
# Check that active object is a mesh
if active_obj.type != 'MESH':
@jmpinit
jmpinit / blender_squiggle.py
Created May 16, 2023 13:14
Draw a squiggle in Blender's Grease Pencil mode via the Python API
import bpy
# Create a new Grease Pencil object to hold the drawing
bpy.ops.object.gpencil_add(location=(0, 0, 0))
grease_pencil = bpy.context.object
grease_pencil.name = "ScriptedGreasePencil"
layer = grease_pencil.data.layers.new("Layer")
grease_pencil.data.layers.active = layer
@jmpinit
jmpinit / fast_image_export.py
Last active June 28, 2023 20:18
Fast image export from Houdini using a Python node. Assumes a grid of points (one per pixel) with Cd set to the pixel color.
from pathlib import Path
import numpy as np
from PIL import Image
node = hou.pwd()
geo = node.geometry()
hip_path = Path(hou.hipFile.path())
render_dir = hip_path.parent / 'render'
image_path = hou.parm('image_out_filename').eval()
@jmpinit
jmpinit / filter-gh-articles.js
Last active May 20, 2023 16:01
A Greasemonkey/Tampermonkey/Violentmonkey user script to automatically remove articles of specific types from the GitHub feed. Also registers disinterest for each of them so they may show up less often.
// ==UserScript==
// @name Remove published releases from GitHub feed
// @namespace Violentmonkey Scripts
// @match https://github.com/
// @grant none
// @version 1.0
// @author Owen Trueblood
// @description Remove published releases from GitHub feed
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js