## joshuazt

Public Snippets 29

### last point on curves

``````if (vertexprimindex(0, @vtxnum) == primvertexcount(0, @primnum) - 1) i@group_root = 1;
if (vertexprimindex(0, @vtxnum) < 1) i@group_root = 1;``````

### mirror chramp

``````// Get mirrored value from @curveu
float u = (abs(@curveu * - 2 + 1) * -1 + 1) / 2;

// Feed that value in a ramp that defines half of the resulting curve
f@pscale = chramp("point_scale", u);``````

### delete by percentage

``````float percentage = chf('percentage');
if(rand(@ptnum, 1) % 100 < percentage) removepoint(0, @ptnum);``````

### scale packed prim

``````float scale = chf('scale');
matrix3 trn = primintrinsic(0, "transform", @primnum);
matrix scalem = maketransform(0, 0, {0,0,0}, {0,0,0}, scale, @P);
trn *= matrix3(scalem);
setprimintrinsic(0, "transform", @primnum, trn);``````

### volume to points

``````float val = f@surface;

### aim normals along surface in a direction

``````vector dir = chv('dir');

float angle = dot(@N, dir);
float fitangle = fit(angle, -1, 1, 0, 1);
float blend = chramp('blend', fitangle);

@Cd = blend;
vector tmp = cross(@N, dir);
vector cross = cross(@N, tmp);

v@N = lerp(@N, cross, blend);``````

### geo to uv space

``````@rest = v@P;

int vtx = pointvertex(0, @ptnum);
vector uv = vertex(0, 'uv', vtx);
v@P = lerp(@P, uv, chf('blend'));``````

### volume to points with val

``````float val = f@surface;

setpointattrib(0, 'val', pt, val);``````

``````float sdf = volumesample(1, 0, v@P);

### geo displacement by map

``````vector cd = point(1, 'Cd', @ptnum);

v@P += normalize(v@N) * fit01(cd.r, -0.5, 0.5) * chf('scale');``````

### dot product with VDB

``````float sdf_amp = volumesample(1,'surface',@P);
vector sdf_dir = volumegradient(1, 'surface', v@P);
sdf_dir = normalize(sdf_dir);

vector pos = point(2, 'P', 0);

@density = dot(sdf_dir, pos);

``````

### Dissipation by SDF

``````float sdf = volumesample(1,0,@P);

if (sdf>0)
{
@density *= fit01(chramp('density', sdf),0,1);
}
``````

### Overlayblending

``````float amp = chf("amp");
int matchpt = @ptnum;
string attr = chs("falloff_attr");
float falloff = point(1, attr, @ptnum);
float b = falloff;
float a = point(0, attr, @ptnum);

float out = 0.0;

if(a < .5)
out = 2.0 * a * b;
else
out = 1.0 - 2.0 * (1.0 - a) * (1.0 - b);

f@attr = lerp(f@attr, out, amp);``````

### Hscript = Details import

``detail(0,"rotx",1)``

### aim normal

``````vector a = @P;
vector b = point(1,'P',0);

@N = b-a;``````

### pointveltovolume

``````int pt = nearpoint(1,@P);
v@vel = point(1,'v',pt);``````