houdini

# houdini

Attribute Transfer with wrangle:

``````string attrib = chs("attribute");
int handle = pcopen(1,"P",@P,ch("rad"),chi("maxpts"));
@`chs("attribute")` =  pcfilter(handle,chs("attribute"));``````

Get available point attribs as a list:

``s[]@attribs = detailintrinsic(0, "pointattributes");``

Collision deformer using Gradient

To move points to the surface of an sdf, add the sdf’s gradient multiplied by the absolute value of the sdf value to the point’s position
Connect the sdf volume with gradient field in the 2nd input
dont forgot to fill the interior of the sdf

``````vector grad = volumegradient(1, 0, @P);
@dist = volumesample(1, 0, @P);
if(@dist <= 0){
@P -= normalize(grad) * @dist;
}``````

Fit a geometry inside a bounding box;

1 – wrangle this
2 – connect geo on 1st input
3 – connect bbox geo in 2nd input

``````vector srcBBmin , srcBBmax;
vector destBBmin , destBBmax;

srcBBmin = getbbox_min(0);
srcBBmax = getbbox_max(0);
destBBmin = getbbox_min(1);
destBBmax = getbbox_max(1);

v@P = fit(v@P,srcBBmin,srcBBmax,destBBmin,destBBmax);``````

Simple spiral

1 – create attribute wrangle , connect nothing
2 – run over > detail(only once)
3 – add below code
4 – then create add sop set to polygon > by group

``````//create parameters;
float turns  = ch("turns");
float length = ch("length");
int   count  = chi("point_count");
vector pos;

pos = 0;

for (int n; n<count ; n++){

Connect nearest point(s)

``````//run in point mode
int maxSearchPoints = chi("maxsearchpoints");
int points[];
points = pcfind(0, "P", @P, 2*searchradius, maxSearchPoints);
foreach(int ptj; points)
{
if(@ptnum == ptj)
continue;
if (ptj < @ptnum)
continue;
int prim = addprim(0, "polyline");
}``````

Set pscale based on distance to the closest point:

``````float searchRad = ch("searchRadius");
//find closest point number with nearpoints function
int closePt = nearpoints(0,@P,searchRad)[1];
//find distance between cur and closest point divide it by half which will be pscale
@pscale = distance(v@P,point(0,"P",closePt))/2;``````

Color By point density:

``````int maxPts = chi("maxPts");
v@Cd = chramp("color",float(@nearCount)/float(maxPts));``````

StickPoints to animated mesh:

``````int primID;
vector primUV ,tempP;
// Offset the points inside the geometry
vector pointOffset = @P - (@N * .1);
// use the offset points to shoot a ray along the normal , To query UV info off the mesh ( static mesh )
primID = intersect(1,pointOffset,@N,tempP,primUV.x,primUV.y);
// Use the UV information, to query the pos information off the animated mesh,
@P = primuv(2,"P",primID,primUV);``````

Point Jitter along surface:

``````int seed        = chi('seed');
vector shift    = rand(@ptnum + seed);
int prims_nb[]  = pointprims(0, @ptnum);
float prims_num = 1 / float( len(prims_nb) );
int prim_choose = int( floor(shift.z / prims_num) );
int prim        = prims_nb[prim_choose];
vector pos      = primuv(0, "P", prim, shift);
@t = prims_num; @P = pos;``````

Delete by Cam Frustrum:

``````v@ndcP= toNDC(chs("cam"),v@P);
``````matrix3 m = maketransform(@N,@up);