Post your favourite Wrangle SOP presets

   108268   38   30
User Avatar
Member
4593 posts
Joined: 2月 2012
Offline
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)
Edited by animatrix_ - 2023年12月10日 07:22:06
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
スタッフ
2540 posts
Joined: 7月 2005
Offline
Please do! We are always looking at adding good presets to the wranglers.
There's at least one school like the old school!
User Avatar
Member
4593 posts
Joined: 2月 2012
Offline
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 );

Edited by animatrix_ - 2023年12月10日 07:22:42
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
183 posts
Joined: 11月 2008
Offline
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);
Aleksei Rusev
Sr. Graphics Tools Engineer @ Nvidia
User Avatar
Member
8668 posts
Joined: 7月 2007
Offline
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);
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
183 posts
Joined: 11月 2008
Offline
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:
Aleksei Rusev
Sr. Graphics Tools Engineer @ Nvidia
User Avatar
Member
4593 posts
Joined: 2月 2012
Offline
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 [ i ] = p [ i ] * xform + t;
    }
    
    int pt [ ];
    for ( int i = 0; i < arraylength ( p ); ++i )
        pt [ i ] = addpoint ( geoself ( ), p [ i ] );
    
    if ( color )
    {
        for ( int i = 0; i < arraylength ( pt ); ++i )
            setattrib ( geoself ( ), "point", "Cd", pt [ i ], -1, c, "set" );
    }

    createLine ( pt [ 0 ], pt [ 1 ] );
    if ( arrow )
    {
        createPolygon ( pt [ 1 ], pt [ 2 ], pt [ 3 ] );
        createPolygon ( pt [ 1 ], pt [ 3 ], pt [ 5 ] );
        createPolygon ( pt [ 1 ], pt [ 5 ], pt [ 4 ] );
        createPolygon ( pt [ 1 ], pt [ 4 ], pt [ 2 ] );
        createPolygon ( pt [ 2 ], pt [ 4 ], pt [ 5 ], pt [ 3 ] );
    }
}

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.
Edited by animatrix_ - 2023年12月10日 09:27:33
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
631 posts
Joined: 11月 2013
Offline

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.
User Avatar
Member
183 posts
Joined: 11月 2008
Offline
jerry7
Convert to polgon to polyline. Use clean sop to remove overlap.

What's the difference with Ends SOP?
Aleksei Rusev
Sr. Graphics Tools Engineer @ Nvidia
User Avatar
Member
631 posts
Joined: 11月 2013
Offline
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.
User Avatar
Member
538 posts
Joined: 12月 2006
Offline
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));
https://gumroad.com/alexeyvanzhula [gumroad.com]
User Avatar
Member
4 posts
Joined: 9月 2014
Offline
v@N = random(@P*123.465) *(vector)2 - 1;

Quick Randomize vector (-1 to 1)
User Avatar
スタッフ
2613 posts
Joined: 7月 2005
Offline
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)));
User Avatar
Member
76 posts
Joined: 9月 2011
Online
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);
}
User Avatar
Member
1267 posts
Joined: 3月 2014
Offline
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!
Werner Ziemerink
Head of 3D
www.luma.co.za
User Avatar
Member
4593 posts
Joined: 2月 2012
Offline
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.
Edited by animatrix_ - 2023年12月10日 09:27:57

Attachments:
attribwrangle.zip (1.2 KB)

Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
4593 posts
Joined: 2月 2012
Offline
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 );
Edited by animatrix_ - 2023年12月10日 09:28:42

Attachments:
attribwrangle.zip (1.1 KB)

Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
1799 posts
Joined: 10月 2010
Offline
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;

-G
User Avatar
Member
1799 posts
Joined: 10月 2010
Offline
oh yeah, set your attribWrangle to run on prims
-G
User Avatar
Member
691 posts
Joined: 6月 2006
Offline
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);
Feel The Knowledge, Kiss The Goat!!!
http://www.linkedin.com/in/alejandroecheverry [linkedin.com]
http://vimeo.com/lordpazuzu/videos [vimeo.com]
  • Quick Links