Skip to content

Instantly share code, notes, and snippets.

@SabinT
SabinT / normalize-verts-blender.py
Last active August 29, 2015 14:20
Normalize (or project to sphere) selected vertices in Blender
import bmesh
def normalize_selected():
m = bpy.context.active_object.data # get selected object's mesh
bm = bmesh.new() # create an empty BMesh
bm.from_mesh(m) # fill it in from a Mesh
for v in bm.verts:
if v.select:
v.co.normalize()
bm.to_mesh(m)
@SabinT
SabinT / blender-get-selected-vertex.py
Last active August 29, 2015 14:20
Get selected vertex in blender
def selected_vertex():
for vert in bpy.context.selected_objects[0].data.vertices:
if vert.select:
return vert;
return None
@SabinT
SabinT / blender-clone-at-vertices.py
Last active July 6, 2019 17:37
Blender - Clone a given object at mesh vertices
# The following function is adapted from
# Nick Keeline "Cloud Generator" addNewObject
# from object_cloud_gen.py (an addon that comes with the Blender 2.6 package)
# Create a clone of object "coypobj" at all vertices in the "verticesFrom" object
# Usage example: cloneAtVertices(bpy.context.scene, bpy.data.objects['ball'], bpy.data.objects['positions'])
def cloneAtVertices(scene, copyobj, verticesFrom):
index = 0;
for v in verticesFrom.data.vertices:
index = index + 1
@SabinT
SabinT / blend-triangle.py
Created May 26, 2015 05:54
Generate blends of three compatible meshes and arrange in a triangle.
# A blender script that creates a triangular grid of different blends of three meshes
# of identical topology in a triangle.
#
# 'a', 'b', and 'c' are the meshes to be blended.
# 'n' is the "height" of the triangle
# 'side' is the length of the side of the triangle in which the
# blended meshes will be arranged
def blendingTriangle(scene, a, b, c, n, side):
index = 0;
# the vertices of the positions
@SabinT
SabinT / FiddlerResponseJsonReplace.cs
Created September 21, 2018 22:31
Replace JSON properties in HTTP response using Fiddler and JSON.NET
// Make sure to add references to Newtonsoft.Json.dll and System.Core.dll into Tools\Options\Scripting\References
// e.g., C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Core.dll;C:\Users\username\AppData\Local\Programs\Fiddler\Newtonsoft.Json.dll
public static void OnBeforeResponse(Session oSession)
{
if (m_Hide304s && oSession.responseCode == 304)
{
oSession["ui-hide"] = "true";
}
if (oSession.oRequest.host == "www.myhost.com" &&
@SabinT
SabinT / stp-pictures.js
Created July 16, 2019 02:02
Download Cascade STP bike pictures in one shot from download page after purchase (medium/full)
function download(url, name) {
fetch(url)
.then(resp => resp.blob())
.then(blob => {
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = name;
document.body.appendChild(a);
@SabinT
SabinT / UnityWaterSinusoidal.hlsl
Last active August 5, 2021 13:59
A water shader in Unity (generates vertex displacement and per-pixel normasl)
#ifndef WaterSineSeries
#define WaterSineSeries
// Based on GPU GEMS, Chapter 1: Effective Water Simulation from Physical Models
// https://developer.download.nvidia.com/books/HTML/gpugems/gpugems_ch01.html
#define TWO_PI 6.2831853
/**
* x,y: coordinates
@SabinT
SabinT / ComplexNumbers.hlsl
Created June 21, 2021 08:24
Some complex number manipulation functions in HLSL (double precision)
double2 cartesianToPolar(double2 z)
{
return double2(length(z), atan2(z.y, z.x));
}
double2 polarToCartesian(double2 p)
{
return double2(p.x * cos(p.y), p.x * sin(p.y));
}
@SabinT
SabinT / TimeLoops.glsl
Created June 21, 2021 08:34
GLSL Time loop tricks
float loopWithPause(float scale) {
// sinusoidal, with a short pause at start/end
float overshoot = 1.5;
// iTime is a variable available in shadertoy.com
// Replace with your own variable as needed
float t = iTime * scale; // scale time here
float a = clamp((mod(t, 2.0) - 1.0) * overshoot, -1.0, 1.0);
return sin(a * PI);
}
@SabinT
SabinT / uvRepeat.glsl
Last active July 6, 2021 06:53
GLSL texture wrapping/repeating
vec2 clamp(vec2 p) {
return clamp(p, 0, 1);
}
vec2 repeat(vec2 p) {
return fract(p);
}
vec2 mirrorRepeat(vec2 p) {
vec2 q = fract(p * 0.5) * 2.0;