find closest point with pcopen vex

   16872   8   3
User Avatar
Member
27 posts
Joined: July 2013
Offline
hey guys
i have simple question how i can find nearest point in vex wrangle ?
like Afaq Sabri = https://vimeo.com/119124511 [vimeo.com]

Attachments:
SHA_2.JPG (60.7 KB)
SHA_1.JPG (77.2 KB)

diue d'amour

HonersforGod@Gmail.com
HonersforGod@Yahoo.com
http://www.youtube.com/user/SHA3254/videos [youtube.com]
User Avatar
Member
2625 posts
Joined: June 2008
Offline
Here is my latest incarnation of detecting my nearest enemy.
Maybe you can adapt it for your use?
Don't forget to close out the point cloud after use or you may leak memory.

Also check out the Proximity VEX code inside the Crowd Trigger itself. (dive into HDA)

float agent_search_radius = 3.0;
int enemyId = -1;
float last_distance = 100000.0;
string group = point(0,“agentgroup”,@id);
int handle = pcopen (0, “P”, @P, agent_search_radius, 1000);
int pcCount = pcnumfound(handle);
for (int i = 0; i < pcCount; i++) {
int pcId = pcimportbyidxi(handle, “point.number”, i);
if (pcId != i@id){
string pcGroup = pcimportbyidxs(handle, “agentgroup”,i);
if (pcGroup != group) {
vector pcPos = pcimportbyidxv(handle, “P”, i);
float pcDistance = length(pcPos - @P);
float current_enemy_health = float_point_attribute(“health”, i);
if (current_enemy_health > 0) {
if (pcDistance < last_distance) {
// This one is closer than last one.
enemyId = pcId;
last_distance = pcDistance;
}
}
}
}
}
pcclose(handle);
if (enemy_id != -1) {
// This is my closest enemy.
int close_id = enemy_id;
float id_distance = last_distance;
}
Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
User Avatar
Member
27 posts
Joined: July 2013
Offline
I did it thanks to afaq sabri and Enivob …… Thanks

Attachments:
image.jpeg (1.8 MB)
image.jpeg (1.8 MB)
image.jpeg (1.8 MB)

diue d'amour

HonersforGod@Gmail.com
HonersforGod@Yahoo.com
http://www.youtube.com/user/SHA3254/videos [youtube.com]
User Avatar
Member
4 posts
Joined: Nov. 2013
Offline
fwiw, when you do a pcopen() in vex, the points are ordered from closest to farthest. also, if you simply restrict your pcopen() to a single point, it will be the one that's closest to your search point.
User Avatar
Member
8786 posts
Joined: July 2007
Offline
as well to get just closest point you can use nearpoint() VEX function
https://www.sidefx.com/docs/houdini14.0/vex/functions/nearpoint [sidefx.com]
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
1798 posts
Joined: May 2006
Online
On a related note, whats the most efficient way to find the closest point to a point? Eg, using this in a wrangle:

i@near = nearpoint(0,@P);

will just return itself. Having a look at the docs, I thought ‘aha, I’ll construct a group pattern to exclude @ptnum':

string me = itoa(@ptnum);
i@near = nearpoint(0,'!'+me,@P);

Ie, if the current point is 5, it creates a group ‘!5’.

This works, but scales terribly; anything over 1000 points slows to a crawl.

I can use nearpoints instead and run through the returned values, selecting the first one that isn't @ptnum:

int nears = nearpoints(0,@P,10,2); // find 2 points within 10 units
foreach (int i ; nears) {
if (@ptnum==i) continue;
@near = i;
}

It scales much better, just curious if I'm missing a cleaner way.
http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
User Avatar
Member
8786 posts
Joined: July 2007
Offline
well, nearpoint() is the best if you don't want to exclude the closest of course, so usually if you are looking up different pointcloud than self

otherwise use for example
int pt = nearpoints(…);

to get the second one
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
1798 posts
Joined: May 2006
Online
See? I knew I was missing a trick.

Thanks!
http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
User Avatar
Member
27 posts
Joined: July 2013
Offline
The remain issue is , i must move point to finde next point . that
The issue . Is there another way to do that without moving the point?


Mr . Alvaro did that with vop point cloud open node
diue d'amour

HonersforGod@Gmail.com
HonersforGod@Yahoo.com
http://www.youtube.com/user/SHA3254/videos [youtube.com]
  • Quick Links