Skip to content

Instantly share code, notes, and snippets.

View aaronjolson's full-sized avatar

Aaron Olson aaronjolson

View GitHub Profile
@aaronjolson
aaronjolson / crush.sh
Created November 21, 2014 17:20
A bash script to be pasted into bashrc. Use the crush command to compress multiple jpgs and pngs inside of a directory. Requires pngcrush and libjpeg-progs
### Crush multiple image files in a folder
crush() {
for f in *;
do
mv "$f" `echo $f | tr ' ' '_'`
done
for f in *.png
do
echo "$f"
@aaronjolson
aaronjolson / blender_select_all_verts.py
Created June 9, 2018 22:09
Blender select all verts on cube
import bpy,bmesh
ob = bpy.data.objects['Cube']
bpy.ops.object.mode_set(mode='EDIT')
mesh=bmesh.from_edit_mesh(bpy.context.object.data)
for v in mesh.verts:
v.select = True
# trigger viewport update
bpy.context.scene.objects.active = bpy.context.scene.objects.active
@aaronjolson
aaronjolson / blender_select_face_normal_y_axis.py
Created June 9, 2018 22:49
Blender script to select the face of a cube with its normal facing the Y axis
import bpy,bmesh
ob = bpy.data.objects['Cube']
bpy.ops.object.mode_set(mode='EDIT')
mesh=bmesh.from_edit_mesh(bpy.context.object.data)
for f in mesh.faces:
if f.normal.y == 1.0:
f.select = True
# trigger viewport update
@aaronjolson
aaronjolson / convert_to_jpeg.py
Last active August 9, 2018 22:02
Converts all png, tif, and bmp files in a directory into jpegs
import os
from PIL import Image
for infile in os.listdir("./"):
print ("file : " + infile)
if infile[-3:] == "tif" or infile[-3:] == "bmp" or infile[-3:] == "png":
outfile = infile[:-3] + "jpeg"
im = Image.open(infile)
print("new filename : " + outfile)
out = im.convert("RGB")
from flask import Flask
from flask import make_response
import os
app = Flask(__name__)
# Simple flask server to be used locally for serving images to get around constraints such as those created
# when trying to load textures in ThreeJs.
# https://stackoverflow.com/questions/24087757/three-js-and-loading-a-cross-domain-image
@aaronjolson
aaronjolson / create_spiral_stairs_in_blender.py
Created February 9, 2019 16:38
Script to create a spiral staircase in blender. As-is, it runs standalone, but it can easily be refactored to integrate it into a project
import bpy
import bmesh
# cleans out the rest of the objects from the scene and puts the cube in, essentially a fresh start, useful for debugging
bpy.ops.object.select_all(action='TOGGLE')
bpy.ops.object.select_all(action='TOGGLE')
bpy.ops.object.delete(use_global=False)
bpy.context.scene.cursor_location = (0.0, 0.0, 0.0)
bpy.ops.mesh.primitive_cube_add(radius=1, view_align=False, enter_editmode=False, location=(0, 0, 0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
@aaronjolson
aaronjolson / select_face_in_blender_and_extrude.py
Created February 9, 2019 16:56
Demonstration of using Python to take an existing mesh, selecting a particular face, and extruding it
import bpy,bmesh
# Assumes we aleady have a cube out, nothing selected
ob = bpy.data.objects['Cube']
bpy.ops.object.mode_set(mode='EDIT')
mesh = bmesh.from_edit_mesh(bpy.context.object.data)
ur_face = None
# look at all of the faces of the cube, find the one that is 'facing' the positive direction on the y axis
for f in mesh.faces:
@aaronjolson
aaronjolson / settings.json
Created January 27, 2021 23:12
Windows terminal config
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"profiles":
@aaronjolson
aaronjolson / material_cleanup.py
Created July 3, 2021 19:21
remove extra materials from all objects in a scene
import bpy
for obj in bpy.context.selected_editable_objects:
obj.active_material_index = 1
for i in range(1, len(obj.material_slots)):
bpy.ops.object.material_slot_remove({'object': obj})
for block in bpy.data.materials:
if block.users == 0:
bpy.data.materials.remove(block)
import bpy,bmesh
ob = bpy.data.objects['Cube']
bpy.ops.object.mode_set(mode='EDIT')
mesh=bmesh.from_edit_mesh(bpy.context.object.data)
for v in mesh.verts:
v.select = True