vesaw55345 Posted May 17, 2024 Share Posted May 17, 2024 I created a simplified example of something I'm working on. I have a list of curves stacked in regular intervals in the y direction. For every point on each curve (starting with the second curve) I want to check whether it's within a certain distance from the closest point on the curve below. If it isn't, then I want to move its x and z coordinate to the value of the closest point from the curve below. I've included the attribute wrangle and the Houdini file. Any thoughts on that? I assume the logic breaks down when there is more than one curve per y- coordinate. But even so my code doesn't really work, since I want every curve to get the distance relative to the already updated curve below. My code works on the original input instead. Do I need to use a solver for that? What I'm trying to do in my project is to get rid of (large) overhangs. So I'm not hung up on doing it on a curve level - if I can for instance advect/erode a VDB to get rid of the overhangs before creating the curves in the first place that would work too. stacking_example.hipnc Quote Link to comment Share on other sites More sharing options...
vesaw55345 Posted May 17, 2024 Author Share Posted May 17, 2024 Somehow I can't edit my original post, so I'm including my vex code here: int numPrims = nprimitives(0); for (int curPrim = 1; curPrim < numPrims; curPrim++) { int pointsBelow[] = primpoints(0, curPrim-1); int pointsOnLine[] = primpoints(0, curPrim); foreach(int p; pointsOnLine) { float minDist = 10000; int closePointIndex = -1; vector thisPos = point(0, "P", p); foreach(int otherP; pointsBelow) { vector otherPos = point(0, "P", otherP); float curDist = distance(thisPos, otherPos); if(p == otherP) { continue; } if(curDist < minDist) { minDist = curDist; closePointIndex = otherP; } } // if point is too far away from closest point below, move x and z coordinate if(minDist > 1.8) { vector newPos = point(0, "P", p); vector closePos = point(0, "P", closePointIndex); newPos.x = closePos.x; newPos.z = closePos.z; setpointattrib(0, "P", p, newPos); addpoint(0, newPos); // just for visualization } } } Quote Link to comment Share on other sites More sharing options...
Aizatulin Posted May 18, 2024 Share Posted May 18, 2024 (edited) There are several problems/issues you'll have to deal with (here are some ideas): as you already mentionend, each curve(prim) needs a unique reference prim. If you sort by Y you can have multiple prims with the same Y-coordinate. if you move the point setting a threshold, every point, which is slightly lower won't move (maybe you can set a smooth transition - ramp based on distance) you probably have to use a feedback loop (with a defined hierarchy based on the Y-coordinate), because if a reverence prim has already moved points you want to use the new points and not the old ones Here is example trying to solve the first problem, but I don't think this will work for every situation. collect all prims, where average y is lower than the current prim sort prims by distance filter by smallest (with tolerance) (expensive) now check for every point the smallest distance to each prim sort by smallest distance and filter by global distance threshold It is possible, that you can have multiple primtives below a curve (or even none). In your example primitive 77 has no reference which is close and primitive 103 has even two which are close. So you probably want to loop over all references (for 77 the list is empty and for 103 you have two elements). stacking_example_mod.hipnc Edited May 18, 2024 by Aizatulin Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.