find closest point with pcopen vex
16666 8 3- Hossein_SHA
- Member
- 27 posts
- Joined: 7月 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]
i have simple question how i can find nearest point in vex wrangle ?
like Afaq Sabri = https://vimeo.com/119124511 [vimeo.com]
diue d'amour
HonersforGod@Gmail.com
HonersforGod@Yahoo.com
http://www.youtube.com/user/SHA3254/videos [youtube.com]
HonersforGod@Gmail.com
HonersforGod@Yahoo.com
http://www.youtube.com/user/SHA3254/videos [youtube.com]
- Enivob
- Member
- 2614 posts
- Joined: 6月 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;
}
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.
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
- Hossein_SHA
- Member
- 27 posts
- Joined: 7月 2013
- Offline
I did it thanks to afaq sabri and Enivob …… Thanks
diue d'amour
HonersforGod@Gmail.com
HonersforGod@Yahoo.com
http://www.youtube.com/user/SHA3254/videos [youtube.com]
HonersforGod@Gmail.com
HonersforGod@Yahoo.com
http://www.youtube.com/user/SHA3254/videos [youtube.com]
- milesvignol
- Member
- 4 posts
- Joined: 11月 2013
- Offline
- tamte
- Member
- 8742 posts
- Joined: 7月 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]
https://www.sidefx.com/docs/houdini14.0/vex/functions/nearpoint [sidefx.com]
Tomas Slancik
FX Supervisor
Method Studios, NY
FX Supervisor
Method Studios, NY
- mestela
- Member
- 1768 posts
- Joined: 5月 2006
- Offline
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.
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.
- tamte
- Member
- 8742 posts
- Joined: 7月 2007
- Offline
- mestela
- Member
- 1768 posts
- Joined: 5月 2006
- Offline
- Hossein_SHA
- Member
- 27 posts
- Joined: 7月 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
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]
HonersforGod@Gmail.com
HonersforGod@Yahoo.com
http://www.youtube.com/user/SHA3254/videos [youtube.com]
-
- Quick Links