Skip to content

Instantly share code, notes, and snippets.

@mattebb
mattebb / gist:4440528
Created January 3, 2013 03:29
Numpy C-API bits
/* ensure array is contiguous, aligned and correct data type */
array = PyArray_FROM_OTF(input_array, NPY_FLOAT32, NPY_CARRAY_RO);
/* reshape the input array to the correct dimensions */
PyArray_Dims dims;
npy_intp shape[2] = {-1, attr.count};
dims.len = 2;
dims.ptr = shape;
array = PyArray_Newshape((PyArrayObject *)array, &dims, NPY_CORDER);
@mattebb
mattebb / getArray.py
Last active December 10, 2015 13:28
Partio NumPy demo
import partio
import numpy as np
p = partio.create()
size = 3
posattr = p.addAttribute("pos",partio.FLOAT,size)
for i in range(8):
p.addParticle()
data = tuple(i+j*100 for j in range(size))
p.set(posattr, i, data)
@mattebb
mattebb / gist:4450615
Created January 4, 2013 07:17
swig code to get partio attribute data as a tuple
%feature("autodoc");
%feature("docstring","Gets a single flattened tuple, containing attribute data for all particles");
PyObject* getTuple(const ParticleAttribute& attr)
{
unsigned int numparticles = $self->numParticles();
PyObject* tuple=PyTuple_New(numparticles * attr.count);
if(attr.type==Partio::INT){
for(unsigned int i=0;i<numparticles;i++) {
@mattebb
mattebb / gist:4545268
Last active December 11, 2015 04:28
Curl Noise (MEL)
// http://soup-dev.websitetoolbox.com/post/curl-noise-for-maya-5937312
pickWalk -d down;
string $part[] = `ls -sl`;
addAttr -ln "noiseFrequency" -at double3 $part[0];
addAttr -ln "noiseFrequencyX" -at double -p noiseFrequency $part[0];
addAttr -ln "noiseFrequencyY" -at double -p noiseFrequency $part[0];
addAttr -ln "noiseFrequencyZ" -at double -p noiseFrequency $part[0];
setAttr -type double3 ($part[0] + ".noiseFrequency") 0.4 0.4 0.4;
setAttr -e-keyable true ($part[0] + ".noiseFrequency");
@mattebb
mattebb / houdini_manual_cook.py
Last active December 12, 2022 18:06
Toggle Manual cook in Houdini
if hou.updateModeSetting() == hou.updateMode.Manual:
hou.setUpdateMode(hou.updateMode.AutoUpdate)
elif hou.updateModeSetting() == hou.updateMode.AutoUpdate:
hou.setUpdateMode(hou.updateMode.Manual)
@mattebb
mattebb / houdini_add_attr_vop.py
Last active December 22, 2015 06:48
Handy shortcut to add an Import Attribute or Add Attribute VOP node, guessing the values of input parameters. Intended for binding to a shortcut key.
selpath = hou.hscriptExpression('mousepath()').split('.')[-1]
voppath = '/'.join( selpath.split('/')[:-1] )
node = hou.node(voppath)
retval, aname = hou.ui.readInput("Attribute Name", buttons=('OK',))
if retval != -1:
add = node.createNode('addattrib')
add.setName("add_%s"%aname)
add.parm('attrib').set(aname)
@mattebb
mattebb / weightedrandom.vex
Last active July 18, 2016 13:29
Weighted random VEX
int i, steps = 80;
float sumhist[], sum=0, slice = 1.0/float(steps);
seed += 123456789;
for (i=0;i<steps;i++) {
float pos = (i*slice);
float val = chramp("__rndweight", pos);
sum += val;
push(sumhist, sum);
}
@mattebb
mattebb / pano.vex.c
Last active August 29, 2015 14:17
Mantra stereo pano camera lens shader (wip)
float theta = -$PI * x;
float phi = $PI * 0.5 * y;
float sin_theta = sin(theta);
float cos_theta = cos(theta);
float sin_phi = sin(phi);
float cos_phi = cos(phi);
i.z = sin_theta * cos_phi;
i.y = sin_phi;
#pragma opname fisheyelens
#pragma oplabel "Fisheye Lens"
#pragma hint x hidden
#pragma hint y hidden
#pragma hint Time hidden
#pragma hint dofx hidden
#pragma hint dofy hidden
#pragma hint aspect hidden
#pragma hint P hidden
@mattebb
mattebb / wn uniforms.glsl
Created March 9, 2022 01:40
Scene data glsl uniforms in Wandering Nets
struct Light {
float intensity;
vec3 colour;
vec3 pa;
vec3 pb;
float w;
vec3 L;
vec3 nL;
};