Showing posts with label connect. Show all posts
Showing posts with label connect. Show all posts

Saturday, 30 March 2019

constraints between two different objects refresh redux ultra

I've probably made a post about this before. Or I thought I did. .. anyway. I only make notes about things as I actually do them :) Repetition is the key to learning !

If you're trying to create constraints between two different objects, say a bunch of bricks and a big big of plaster wall you have to approach your primitive constraints generation a little differently than usual.
Normally you would put a Connect Adjacent Pieces node down and this would draw lines between your closest points. However if you were to merge the bricks and plaster together and do this, you still end up with lines being generated between brick bits and plaster bits..when all you actually want are the lines exclusively between brick & plaster. Whew.

To achieve this you have to hijack the name attribute of your brick and plaster geometry so that Houdini thinks there are only two names to connect between. Instead of having "brick01,brick02,brick03,plaster01,plaster02,plaster03" you will have "brick,plaster". that's it.
In a Point Wrangle(for packed geo) or a Primitive Wrangle(if you are working with unpacked geo) for each of your objects do something like this -

s@original_name=@name;
s@name="objectA";

where objectA might be "brick", object B might be "plaster". Now merge these two mono-named objects together , promote the name  attribute to point level (if it isn't already) and apply the Connect Adjacent Pieces node to them. Now you should only see lines being generated between the two seperate groups of objects. Brick to Plaster. Plaster to Brick.
Finally you must bring back your original name, so use an attribute rename node for this..


Plug your nice sparkly constraints into the rest of your network!


Friday, 29 September 2017

connecting points again..


Here're two expanded ways of connecting groups of points together!




The first method relies on you creating an attribute in a preceding point wrangle called "id". This is the value you'll search for, when making connections. The "destination" points go into the first input, the origin points go into the second.

int count = findattribvalcount(1,"point","id",i@id);

for (int i = 0; i < count; i++) {
    int find = findattribval(1,"point","id",i@id,i);
    
    int prim = addprim(0,"polyline");
    
    vector p2 = point(1,"P",find);
    
    int pt = addpoint(0,@ptnum);
    setpointattrib(0,"P",pt,p2);
    
    addvertex(0,prim,@ptnum);
    addvertex(0,prim,pt);
}


LINE BY LINE

int count = findattribvalcount(1,"point","id",i@id);
//count number of points that have the "id" value
for (int i = 0; i < count; i++) {
//start for loop, for the number of points it has found
    int find = findattribval(1,"point","id",i@id,i);
    //get point number for point that has the id value. The last i is the index of the for loop.
    int prim = addprim(0,"polyline");
    //add primitive, of polyline type
    vector p2 = point(1,"P",find);
   //create position vector based on point number found 
    int pt = addpoint(0,@ptnum);
//create point at the position of current point
    setpointattrib(0,"P",pt,p2);
    //set position of just created point to the vector created
    addvertex(0,prim,@ptnum);
//add vertex to the primitive at current point position
    addvertex(0,prim,pt);
//add vertex to the primitive at found point position
}





This method doesn't need the "id" value, but just grabs the closest point to it. Again the many destinations go into the first input and the few "origins" go to the second.

int nearpt = nearpoint(1,@P);
int prim = addprim(0,"polyline");
vector p2 = point(1,"P",nearpt);
int pt = addpoint(0,@ptnum);
setpointattrib(0,"P",pt,p2);
addvertex(0,prim,@ptnum);
addvertex(0,prim,pt);


LINE BY LINE

int nearpt = nearpoint(1,@P);
//get id number of point from second input to currently processed point's position
int prim = addprim(0,"polyline");
//create primitive of polyline type
vector p2 = point(1,"P",nearpt);
//set vector to nearpt's position
int pt = addpoint(0,@ptnum);
//add point at currently processed point's position
setpointattrib(0,"P",pt,p2);
//set position of new point to position of nearpt.
addvertex(0,prim,@ptnum);
//add vertex at currently processed point's position
addvertex(0,prim,pt);
//add vertex at nearpt's position