Hi, sorry for the newbie question but I've been looking for how to do this for quite a while now!
In the HDK, how do I find the number of the closest point in my gdp to a world position? For example, I want to find the number of the point in my geometry that is closest to position (1,2,3).
I have seen the classes like UT_PointTree, but I can't for the life of me get them initialized properly. Anyone have an example?
HDK: Get closest point
4869 7 1- KMcNamara
- Member
- 228 posts
- Joined: Dec. 2012
- Offline
- graham
- Member
- 1908 posts
- Joined: Nov. 2006
- Offline
Something like this should work:
#include <GEO/GEO_PointTree.h>
GA_Offset
getNearestPoint(const GU_Detail *gdp, const UT_Vector3D &pos, fpreal maxdist)
{
GEO_PointTreeGAOffset tree;
tree.build(gdp);
// Get the offset of the nearest point, within maxdist.
return tree.findNearestIdx(pos, maxdist);
}
#include <GEO/GEO_PointTree.h>
GA_Offset
getNearestPoint(const GU_Detail *gdp, const UT_Vector3D &pos, fpreal maxdist)
{
GEO_PointTreeGAOffset tree;
tree.build(gdp);
// Get the offset of the nearest point, within maxdist.
return tree.findNearestIdx(pos, maxdist);
}
Graham Thompson, Technical Artist @ Rockstar Games
- KMcNamara
- Member
- 228 posts
- Joined: Dec. 2012
- Offline
- neil_math_comp
- Member
- 1743 posts
- Joined: March 2012
- Offline
Just as a warning, if you'll be doing a lot of closest point queries, you'll definitely want to save the GA_PointTreeGAOffset, instead of recomputing it every time, and in that case, I seem to recall that you can save even more time by reusing the same results queue and passing it into the closest point query. I don't remember the class name, but it'd be in UT_KDTree.h; GEO_PointTreeGAOffset is a subclass of UT_KDTree. It's something along the lines of ut_KDQueue, I think.
Oh, and feel free to ask any questions. It's especially important for “newbies” to ask, since it can be pretty difficult to get started with the HDK, and it'd be unfortunate if there wasn't adequate help. :wink:
Oh, and feel free to ask any questions. It's especially important for “newbies” to ask, since it can be pretty difficult to get started with the HDK, and it'd be unfortunate if there wasn't adequate help. :wink:
Writing code for fun and profit since... 2005? Wow, I'm getting old.
https://www.youtube.com/channel/UC_HFmdvpe9U2G3OMNViKMEQ [www.youtube.com]
https://www.youtube.com/channel/UC_HFmdvpe9U2G3OMNViKMEQ [www.youtube.com]
- KMcNamara
- Member
- 228 posts
- Joined: Dec. 2012
- Offline
- neil_math_comp
- Member
- 1743 posts
- Joined: March 2012
- Offline
KMcNamara
Do you know if there's similar functionality for faces? I'd like to find the closest face and its normal to a given point.
I think UT_RTree does something like that, though I've never used it. I think it's queried (maybe even lazily constructed?) by calling UTgetIntersectingItems, though I don't know if it'd just say yes/no whether something intersects. GU_RayIntersect can find things like the minimum distance from primitives to a ray, so it might have something like that too, but I'm not sure.
Writing code for fun and profit since... 2005? Wow, I'm getting old.
https://www.youtube.com/channel/UC_HFmdvpe9U2G3OMNViKMEQ [www.youtube.com]
https://www.youtube.com/channel/UC_HFmdvpe9U2G3OMNViKMEQ [www.youtube.com]
- KMcNamara
- Member
- 228 posts
- Joined: Dec. 2012
- Offline
Ah, found a good answer here: http://forums.odforce.net/topic/12691-closest-point-on-the-primitive/?p=79743 [forums.odforce.net]
Thanks!
Thanks!
- KMcNamara
- Member
- 228 posts
- Joined: Dec. 2012
- Offline
So now I'm trying to use proximityPoint to get a collection of primitives around the point. However, I'm getting a segfault with this - ideas? Not sure if I'm doing the right thing with the GU_ProximityHelper?
GU_RayIntersect rint(gdp);
UT_Array<GU_MinInfo> hitList;
const GU_ProximityHelper* proxyHelp;
rint.proximityPoint(hitList, UT_Vector3(0.0,1.0,0.0), true, proxyHelp, 1.0);
for (auto i = hitList.begin(); i != hitList.end(); ++i)
{
i.item().prim()->computeNormal(); // Just see if we can access the prim
}
GU_RayIntersect rint(gdp);
UT_Array<GU_MinInfo> hitList;
const GU_ProximityHelper* proxyHelp;
rint.proximityPoint(hitList, UT_Vector3(0.0,1.0,0.0), true, proxyHelp, 1.0);
for (auto i = hitList.begin(); i != hitList.end(); ++i)
{
i.item().prim()->computeNormal(); // Just see if we can access the prim
}
-
- Quick Links