Search - User list
Full Version: Post your favourite Wrangle SOP presets
Root » Houdini Lounge » Post your favourite Wrangle SOP presets
animatrix3d
Everyone has set up their own set of Wrangle code presets. It would be useful if we shared some of our favourites here both for learning and speeding up work. Maybe SESI would add some of these to H14 for everyone.

I will get the ball rolling:

Group by Neighbour Count
if ( neighbourcount ( 0, @ptnum ) == chi(“count”) )
setpointgroup ( geoself ( ), chs(“name”), @ptnum, 1, “set” );
Parameters:

int count (Neighbour Count)
string name (Group Name)
old_school
Please do! We are always looking at adding good presets to the wranglers.
animatrix3d
Thanks Jeff I am sure people have a lot better ones, but here's another one I use that works for any element (point, prim, vertex):

Color Random

float seed = 0.99 + ch(“seed”);
float r = hscript_rand ( @ptnum + seed + sin ( 13 * @ptnum + 19 * seed ) );

float s = fit ( random ( 17 * @ptnum + 91 * seed ), 0, 1, ch(“srangex”), ch(“srangey”));
s = ch(“s”) * ( 1 - ch(“srand”) ) + s * ch(“srand”) * ch(“s”);

float val = fit ( random ( 173 * @ptnum + 11 * seed ), 0, 1, ch(“vrangex”), ch(“vrangey”));
val = ch(“v”) * ( 1 - ch(“vrand”) ) + val * ch(“vrand”) * ch(“v”);

@Cd = hsvtorgb ( ( r + 0.618033988749895 ) % 1, s, val );

Stalkerx777
Creates a point in the center of each primitive.
This is for AttribWrangle SOP, run over primitives:


int numvertex = primvertexcount(0, @primnum);
int vt = vertexpoint(0, vertexindex(0, @primnum, 0));
vector ptpos = point(0, “P”, vt);
for(int i=1; i < numvertex; i++)
{
int pt_n = vertexpoint(0, vertexindex(0, @primnum, i));
ptpos += point(0, “P”, pt_n);
}
vector centroid = ptpos/numvertex;
int newpt = addpoint(0, centroid);
vector prim_n = prim_normal(0, @primnum, @s, @t);
removeprim(0, @primnum, 1);
tamte
Stalkerx777
Creates a point in the center of each primitive.
This is for AttribWrangle SOP, run over primitives:
Wouldn't this be enough?addpoint(0, @P);
removeprim(0, @primnum, 1);
Stalkerx777
tamte
Stalkerx777
Creates a point in the center of each primitive.
This is for AttribWrangle SOP, run over primitives:
Wouldn't this be enough?addpoint(0, @P);
removeprim(0, @primnum, 1);

Heh, yes, you right Tomas This code is my old one, my shame :wink:
animatrix3d
Create arrow geometry which is useful for gnomons:



int createLine ( int pt0; int pt1 )
{
int pr = addprim ( geoself ( ), “polyline” );
addvertex ( geoself ( ), pr, pt0 );
addvertex ( geoself ( ), pr, pt1 );
return pr;
}

int createPolygon ( int pt0; int pt1; int pt2 )
{
int pr = addprim ( geoself ( ), “poly” );
addvertex ( geoself ( ), pr, pt0 );
addvertex ( geoself ( ), pr, pt1 );
addvertex ( geoself ( ), pr, pt2 );
return pr;
}

int createPolygon ( int pt0; int pt1; int pt2; int pt3 )
{
int pr = addprim ( geoself ( ), “poly” );
addvertex ( geoself ( ), pr, pt0 );
addvertex ( geoself ( ), pr, pt1 );
addvertex ( geoself ( ), pr, pt2 );
addvertex ( geoself ( ), pr, pt3 );
return pr;
}

void createAxisGeometry ( float s; vector n; vector t; vector c; int color; int arrow; int scale )
{
vector p ;
push ( p, 0 );
push ( p, set ( s, 0, 0 ) );

if ( arrow )
{
float x = scale ? 0.75 * s : s - 0.25;
float y = 0.03 * ( scale ? s : 1 );
push ( p, set ( x, y, y ) );
push ( p, set ( x, y, -y ) );
push ( p, set ( x, -y, y ) );
push ( p, set ( x, -y, -y ) );
}

for ( int i = 0; i < arraylength ( p ); ++i )
{
matrix3 xform = dihedral ( { 1, 0, 0 }, { 0, 0, -1 } ) * lookat ( 0, n );
p = p * xform + t;
}

int pt ;
for ( int i = 0; i < arraylength ( p ); ++i )
pt = addpoint ( geoself ( ), p );

if ( color )
{
for ( int i = 0; i < arraylength ( pt ); ++i )
setattrib ( geoself ( ), “point”, “Cd”, pt , -1, c, “set” );
}

createLine ( pt , pt );
if ( arrow )
{
createPolygon ( pt , pt , pt );
createPolygon ( pt , pt , pt );
createPolygon ( pt , pt , pt );
createPolygon ( pt , pt , pt );
createPolygon ( pt , pt , pt , pt );
}
}

createAxisGeometry ( ch(“s”), chv(“n”), chv(“t”), chv(“c”), chi(“color”), chi(“arrow”), chi(“scale”) );



You need to create Cd point attribute before the AttribWrangle as AFAIK there is no other way to do this in code for points since setpointattrib doesn't create a new attribute and this code runs in Detail mode.
jerry7

for(int i = 0; i< @numvtx; i++){

int vtx1,vtx2;
if(i<@numvtx-1){
vtx1 = i;
vtx2 = i+1;
}
else{
vtx1 = i;
vtx2 = 0;
}


int lvtx1 = vertexindex(0,@primnum,vtx1);
int pt1 = vertexpoint(0,lvtx1);

int lvtx2 = vertexindex(0,@primnum,vtx2);
int pt2 = vertexpoint(0,lvtx2);

int prim = addprim(0,“polyline”);
addvertex(0,prim,pt1);
addvertex(0,prim,pt2);
}

removeprim(0,@primnum,0);

Convert to polgon to polyline. Use clean sop to remove overlap.
Stalkerx777
jerry7
Convert to polgon to polyline. Use clean sop to remove overlap.

What's the difference with Ends SOP?
jerry7
Stalkerx777
What's the difference with Ends SOP?
Ends convert one primitive to one polyline。These code convert one segment to one polyline after that can do something foreach segment.
vux
Orient piece of geometry by 4 points:
1. src_pt - source point 1
2. dst_pt - destination point 1
3. src_opt - source point 2
4. dst_opt - destination point 2

int src_pt = 10 ;
int dst_pt = 2 ;
int src_opt = 11 ;
int dst_opt = 3 ;
vector4 q = dihedral( point(geoself(), “P”, src_pt)-point(geoself(), “P”, src_opt), point(geoself(), “P”, dst_pt)-point(geoself(), “P”, dst_opt) );
@P = qrotate(q, @P)+point(geoself(), “P”, dst_pt)-qrotate(q, point(geoself(), “P”, src_pt));
Ferry Taswin
v@N = random(@P*123.465) *(vector)2 - 1;

Quick Randomize vector (-1 to 1)
mark
Ferry Taswin
v@N = random(@P*123.465) *(vector)2 - 1;

Quick Randomize vector (-1 to 1)

Don't you want to normalize the vector as well?
v@N =normalize(random(@P*123.465)) *(vector)2 - 1


Edit: but in H14.0, you might want to look at the new sample_direction_uniform function. For example:
v@N = sample_direction_uniform(vector2(random(@ptnum)));
jkunz07
Here is one to clip points similar to the clip sop:

float dotprod = dot(chv(“clip_dir”),normalize(chv(“clip_pos”)-@P));

if( dotprod > 0 )
{
removepoint(geoself(),@ptnum);
}
Werner Ziemerink
tamte
Stalkerx777
Creates a point in the center of each primitive.
This is for AttribWrangle SOP, run over primitives:
Wouldn't this be enough?addpoint(0, @P);
removeprim(0, @primnum, 1);

brilliant…Thanks!
animatrix3d
Peak SOP with the ability to use any attributes for Normal and Scale

float s = 1;
if ( chi(“scale”) )
s = @scaleAttribute;

@P += normalize ( @N ) * ch(“amount”) * pow ( s, ch(“exponent”) );

I attached the preset that has the right parameters and mapping. You can add this to your tab menu and completely replace the standard Peak SOP.
animatrix3d
Proximity

Preset attached complete with parameters.

int source = chi(“source”);
int index = 1 - source;
int maxpts = chi(“maxpts”) + index;
int handle = pcopen ( source, “P”, @P, ch(“maxdist”), maxpts );
int count = pcnumfound ( handle );
if ( count > index )
{
int pt = pcimportbyidxi ( handle, “point.number”, index );
float dist = pcimportbyidxf ( handle, “point.distance”, index );

i@nearestpt = pt;
@nearestdist = dist;
}
i@nearestcount = count - index;
pcclose ( handle );
grayOlorin
marks prims with normals facing away from the origin with an attribute



vector primN = prim_normal(0, @primnum, 0, 0);

i@awayFacing = dot(primN, -@P) < 0 ? 1 : 0;

grayOlorin
oh yeah, set your attribWrangle to run on prims
Alejandro Echeverry
Random Orientation for Copy instancing


vector randDir = set(rand(@ptnum+252+ch(“seed”)),rand(@ptnum+281+ch(“seed”)),rand(@ptnum+294+ch(“seed”)));
float angle = fit01(rand(@ptnum+741+ch(“seed”)),-3.14,3.14);
p@orient = set(randDir.x,randDir.y,randDir.z,angle);
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB