Skip to content

Instantly share code, notes, and snippets.

@tamask
tamask / action_simplify.py
Created November 30, 2020 16:46
Blender addon: Use Simplify F-Curves on any action visible in the graph editor.
import bpy
import curve_simplify
bl_info = {
'name': 'Simplify Action',
'author': 'Tamas Kemenczy',
'version': (0, 1),
'blender': (2, 91, 0),
'description': 'Use Simplify F-Curves on any action visible in the graph editor.',
'category': 'Add Curve',
@tamask
tamask / fetch-iphone-photos.py
Last active November 17, 2020 19:10
Utility script for downloading photos/images from the iPhone. Optionally converts HEIC files to JPG with `heif-convert` util. Meant for Linux but could work elsewhere. `heif-convert` is available through the `libheif-examples` package on Ubuntu, for example.
#!/usr/bin/env python
# HEIC image conversion depends on the heif-convert cmd utility,
# available through the `libheif-examples` package on Ubuntu, for example.
import os
import glob
import argparse
import datetime
import shutil
@tamask
tamask / plot.py
Created July 28, 2019 20:29
Blender 2.80 plotter
import bpy
import bmesh
NAME = '(Plot)'
def line(gen, name=NAME):
"""Plot arbitrary x,y values as line"""
with Plotter(name) as p:
for x, y in gen:
p.extend(x, y)
@tamask
tamask / export_svg_lines.py
Last active September 18, 2019 07:23
Export xy-plane bezier/poly lines as svg outlines.
import os
import bpy
import math
import mathutils
bl_info = {
'name': 'Export SVG Lines (.svg)',
'author': 'Tamas Kemenczy',
'version': (0, 1),
'blender': (2, 6, 9),
@tamask
tamask / Mathutil.cginc
Created February 28, 2019 10:58
Various math util functions for cg
#ifndef _MATHUTIL
#define _MATHUTIL
#define PI 3.141592653589793115997963468544185161590576171875
inline float floorq(float v, float q) {
return floor(v / q) * q;
}
inline float ceilq(float v, float q) {
@tamask
tamask / Billboard.cginc
Last active February 28, 2019 10:59
Matrix for shader-based billboarding in Unity
#ifndef _BILLBOARD
#define _BILLBOARD
#include "UnityCG.cginc"
/*
About BILLBOARD_MATRIX
----------------------
@tamask
tamask / io_export_curve.py
Created February 8, 2019 11:42
Blender: Export the active curve object (U-component only)
# This exporter just serializes Blender's bpy curve data API verbatim,
# so the exported json structure mirrors the variable names and
# arrays. The exporter only goes so far to export the U-component of
# the curve data, since we're more interested in curves and not NURBS
# surfaces for use in videogames. An asset importer in Unity need only
# look up the Blender Python API to choose how to interpret this data.
import bpy
import json
from bpy_extras.io_utils import ExportHelper
@tamask
tamask / Color.cginc
Last active February 28, 2019 10:59
Unity color conversion and uv-encoded color unpacking
#ifndef _COLOR
#define _COLOR
inline float3 hue2rgb(in float h)
{
float r = abs(h * 6 - 3) - 1;
float g = 2 - abs(h * 6 - 2);
float b = 2 - abs(h * 6 - 4);
return saturate(float3(r, g, b));
}
@tamask
tamask / uvdata.py
Created January 29, 2019 11:03
Simple tool for packing colors into UV maps
'''
Simple tool for packing colors into UV maps
'''
import bpy
import math
import mathutils
def v2_to_float(v2, precision=4096):
'''Pack two 0-1 float values into a single float'''
@tamask
tamask / MeshInfo.cs
Created January 15, 2019 12:34
Unity: display mesh info for selected object
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(MeshFilter))]
public class MeshInfo : Editor {
protected MeshFilter meshFilter;
protected Mesh mesh;
protected Vector3[] lines;
public void OnEnable() {