theOutsider Posted September 15, 2019 Share Posted September 15, 2019 Hi guys, I wanted to ask how can I achieve the following result: I have points scattered along a surface, on wich I have various noises affecting the color attributes of said points. What I want is for the points that are in the "red" zone to not move at all, and for the points in the "blue" to find the closest RED neighbour, and move towards it, controlled by a slider for me to animate. Seems easy enough, but alas, I am stuck. I wrote a point wrangle that does the job - well, sort of. The points are separated correctly, but I can't find an efficient way to attract them to the closest "red" neighbour. Most of them move, but not in a complete way as to seem as pure attraction. This is what I 've got so far: int nearpt = pcfind(0, "P", @P, chf("neighbourRad"), 2)[1]; i@nearpt = nearpt; string @INstatic = ""; //to separate the points in teams if (@Cd >= ch("color_tolerance")) { @INstatic = "yes"; @Cd = {1,0,0}; } else if (@Cd < ch("color_tolerance")){ @INstatic = "no"; @Cd = {0, 1, 1}; } //find closest points int ptneighbours [] = pcfind(0, "P", @P, 10, 1000); i[]@ptneighbours = ptneighbours; foreach(int j; i[]@ptneighbours) { s@affected = point(geoself(), "INstatic", j); if ( @affected == "yes") { @nearpt = j; v@nearPos = point(0, "P", @nearpt); } else { v@nearPos = point(0, "P", @nearpt); } } //move only blue closest points if( @INstatic == "no") { @P = lerp(@P, @nearPos, chf("percentcomplete")); } Any help would be more than appreciated, G. Quote Link to comment Share on other sites More sharing options...
anim Posted September 16, 2019 Share Posted September 16, 2019 you can't do this 4 hours ago, theOutsider said: s@affected = point(geoself(), "INstatic", j); in the same wrangle as this 4 hours ago, theOutsider said: @INstatic = "yes"; the point(0, ...) or point(geoself(), ...) will just read from the input geo where INstatic is not populated yet so maybe try to split it into 2 wrangles Quote Link to comment Share on other sites More sharing options...
theOutsider Posted September 16, 2019 Author Share Posted September 16, 2019 Hi Anim and thank you very much for your reply!! Yeah, figured as much - I actually have it as two separate wrangles in my project, I only merged them to post here. I will try and clean ti up better today though! Other than that, I know that the code is fugly and probably quite inefficient, but am I even on the right path? Or is it something that I am missing in logic? It goes without saying that, if anybody has any better idea to tackle the end result differently (vop, sop, pop whatever) please, feel free to share! Quote Link to comment Share on other sites More sharing options...
Librarian Posted September 16, 2019 Share Posted September 16, 2019 (edited) Hm can you post some examples of what you want to achieve exactly ... I posted point vop that do those stuff based on noise play with that file. qlib have some examples but with particles maybe that can help. Edited September 16, 2019 by srletak Quote Link to comment Share on other sites More sharing options...
3dome Posted September 16, 2019 Share Posted September 16, 2019 i would assume this is a more efficient - and I would say simpler - way: if(@Cd.x < .5) //do the operations only on the blue points { int near = nearpoint(0, "\x40Cd.x>.9", @P); //find the nearest neighbour but already limit the points to sample to the red ones vector p = point(0, "P", near); @P = lerp(@P, p, ch("percentcomplete")); } for a bit more "organic" movement you could do something like this: if(@Cd.x < .5) { int near = nearpoint(0, "\x40Cd.x>.9", @P); vector p = point(0, "P", near); float b = fit(@Frame, 1, distance(@P, p)*125, 0, 1); @P = lerp(@P, p, b); //blend the positions over a certain amount of time based on the distance between the blue and red point, so distant points take longer to complete the lerp() } Quote Link to comment Share on other sites More sharing options...
theOutsider Posted September 16, 2019 Author Share Posted September 16, 2019 (edited) 2 hours ago, srletak said: Hm can you post some examples of what you want to achieve exactly ... I posted point vop that do those stuff based on noise play with that file. qlib have some examples but with particles maybe that can help. @srletak thank you friend! I actually saw your file the other day, but I was probably too burnt out from the wrangle to utilise it correctly - I will look it up in more detail today though! As for the qlib, it seems promising, never thought about checking it, you're right! @3dome I just saw your code - you sir, are quite possibly a genius! What took me 2 days to figure out, a messed up code and hundreds of variables and arrays to do, you managed to do in just 6 lines of code !! Thanks, I am looking at it right now and will get back to you with the results! @3dome I checked it and it works beautifully - thank you so, so much (and everybody else taking the time to help - you rock!)! On a related note, how can I make sure that all these points don't overlap, but instead "stack" on / close to each other? Kinda like sand / dust gathering? Edited September 16, 2019 by theOutsider Quote Link to comment Share on other sites More sharing options...
3dome Posted September 16, 2019 Share Posted September 16, 2019 (edited) happy to help not in front of Houdini right now, but if you don't want to have them stack up you could either just use a point relax SOP (maybe only on the blue points) or not blend all the way to 1 (-> percentcomplete) but stop a bit earlier, randomized per point Depending on how detailed you need to go, you could factor in pscale (if present) but sooner or later things will break and you'd be better of using a solver Edited September 16, 2019 by 3dome 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.