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;
      float mask;
      float rad;
      float radRamp;
      float radmult = ch("rad");
      
      pos = 0;
      
      for (int n; n<count ; n++){
          mask = (n/float(count));
          radRamp = chramp("radius_ramp",mask);
          radRamp = fit(radRamp,0,count,0,1);
          rad = radRamp * radmult * 1000;
          pos = set(sin(mask*turns)*rad,-cos(mask*turns)*rad,mask*length);
          addpoint(0,pos);

      Connect nearest point(s)

      //run in point mode
      float searchradius = ch("searchradius");
      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");
          addvertex(0, prim, @ptnum);
          addvertex(0, prim, ptj);
      }

      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");
      i@nearCount = len(nearpoints(0,@P,ch("rad"),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);
      float padding = chf("padding");
      float nearclip = chf("nearclip");
      if([email protected] > (1 + padding) || [email protected] < (0 - padding) || [email protected] > (1 + padding) || [email protected] < (0 - padding) || [email protected] < nearclip){
          removepoint(0,@ptnum);
      }

      To Convert a Vector to matrix:

      matrix3 m = maketransform(@N,@up);
      p@orient  = quaternion(m);