Showing posts with label addpoint. Show all posts
Showing posts with label addpoint. Show all posts

Saturday 16 September 2017

Entagma snippet : drawing lines between a set of two points

This is useful when you want to connect two bunches of points together.. You'd think it'd be easy right?

Scatter, say 50, points on a grid. Then another 50 on another grid (or any shape..it doesn't really matter). Move them about a bit, then plug them both into a point wrangle (first two inputs).
This code will draw a single primitive edge between the points, paired by @ptnum (so you could do some sort of sorting beforehand, I guess):


int npnt=addpoint(0, @opinput1_P);

int nprim=addprim(0,"polyline");

addvertex(0,nprim,@ptnum);

addvertex(0,nprim,npnt);

Lets tackle each line.

int npnt=addpoint(0,@opinput1_P);
First we make a new point. Point wrangles only ever consider the first input's points. So we need to add the other input's points into the mix. I think the 0 corresponds to the @ptnum attribute.. So it looks up the relevant point in input1 and then puts it at the position specified by "@opinput1_P". That's a handy bit of VEX shortcutting there.

int nprim=addprim(0,"polyline");
Here we are creating a new primitive, of polyline type. Nothing is there yet...

addvertex(0,nprim,@ptnum);
Now we add a vertex to the primitive we just created. Firstly, we add the point we're currently processing.

addvertex(0,nprim,npnt); 
Next we add the vertex we added at the beginning (our currently processed point's counterpart in the other group).

That's it!

Thursday 5 January 2017

add point to centre of primitive and have UVs (sort of)

Just to add points and then remove the primitive.

addpoint(0, @P);
removeprim(0, @primnum, 1);



This goes into a primitve wrangle!


To also have UVs:

vector uv = primuv(0,"uv",@primnum,set(0.5,0.5,0));


int pt = addpoint(0,@P);
removeprim(0, @primnum, 1);


setpointattrib(0,"uv2",pt,uv,"set");


Above this wrangle node, we'd initialise the uv2 value. After it, we'd rename the attribute to "uv". For some reason Houdini doesn't like it when you have UVs in both point and vertex.