Skip to content

Instantly share code, notes, and snippets.

@tamask
tamask / qsort.js
Created July 13, 2011 14:51
In-place, non-recursive qsort in Javascript
function qsort(a, k, l, r) {
// a: array to sort, k: key to sort by,
// l, r: optional array index array range
// i: stack index, s: stack,
// p: pivot index, v: pivot value,
// t: temporary array item,
// x, y: partion low/high
var i, s, p, v, t, x, y;
@tamask
tamask / add_random_object.py
Created October 12, 2011 02:17
Add Random Object
import bpy
import random
bl_info = {
'name': 'Add Random Object',
'version': (0, 0, 0),
'blender': (2, 5, 9),
'category': 'Object',
'description': 'Pick a random object and add it at the cursor',
}
@tamask
tamask / packer.py
Created November 19, 2011 19:36
Simple box packer (no rotations)
EPSILON = 0.000001
def approx_eq(a, b):
return abs(a - b) < EPSILON
def get_item_or_attr(obj, attr):
try:
return obj[attr]
except (TypeError, KeyError):
return getattr(obj, attr)
@tamask
tamask / io_export_actions.py
Created December 7, 2011 15:58
Export Blender Actions (.json)
import bpy
import json
json.encoder.c_make_encoder = None
json.encoder.FLOAT_REPR = lambda o: format(o, '.6f')
actions = []
for action in bpy.data.actions:
a = {
'name': action.name,
@tamask
tamask / interpolate_bezier.js
Created December 7, 2011 17:05
interpolate_bezier
function interpolate_bezier(a, b, c, d, resolution) {
/* Blender's forward differencing bezier interpolation */
var p = [];
var res = resolution - 1;
var dims = Math.max(
a.length, b.length, c.length, d.length);
for (var i = 0; i < res; i++) {
var x = [];
@tamask
tamask / texpack_css.py
Created December 9, 2011 17:16
texpack atlas to css (default texpack format)
import sys
atlas = sys.stdin.read()
for item in atlas.split('\n'):
if not item:
continue
tokens = item.split('\t')
atlas = tokens[0]
@tamask
tamask / bake_vertex_colors.py
Created December 27, 2011 17:28
Bake Vertex Colors
import bpy
bl_info = {
'name': 'Bake Vertex Colors',
'author': 'Tamas Kemenczy',
'version': (0, 1),
'blender': (2, 6, 1),
'location': 'View3D > Specials > Bake Vertex Colors',
'description': 'Bake the active uv texture image to vertex colors',
'category': 'Mesh'
@tamask
tamask / vertexpaint.py
Created December 29, 2011 18:39
blender vertex paint function
import bpy
from mathutils import Color
MODES = {
'=': lambda a, b: b,
'+': lambda a, b: a + b,
'-': lambda a, b: a - b,
'*': lambda a, b: Color((a.r * b.r, a.g * b.g, a.b * b.b)),
'/': lambda a, b: Color((a.r / b.r, a.g / b.g, a.b / b.b)),
}
@tamask
tamask / adjust_vertex_colors.py
Created January 2, 2012 12:03
Adjust Vertex Colors
import bpy
bl_info = {
'name': 'Adjust Vertex Colors',
'author': 'Tamas Kemenczy',
'version': (0, 1),
'blender': (2, 6, 1),
'location': 'View3D > Specials > Adjust Vertex Colors',
'description': 'HSV vertex color adjustment of the selected faces',
'category': 'Mesh'
@tamask
tamask / vertexpaint.py
Created April 25, 2012 04:09
vertex color adjustment (bmesh)
def paint(mesh, fn):
c = mesh.vertex_colors.active.data
for p in mesh.polygons:
if p.select:
for i in p.loop_indices:
c[i].color = fn(c[i].color)