hello all,
I am trying to get the closest point in hom. So far I got this:
# This code is called when instances of this SOP cook.
geo = hou.pwd().geometry()
ref = hou.node(“/obj/geo/ref”).geometry()
for p in geo.points():
pos = p.position()
result = ref.nearestPrim(pos,pos,pos)
if result:
#find the point that belongs to the u and v on that prim
What would be the next step to actual get a xyz position?
I am trying to loop over a set of points, snap 1 point to the surface, move the next point to this same position with the same offset they had before the snapping, snap this point etc. Is there a way to do this in vops?
Cheers,
Koen
Closest point / ray sop in HOM
5765 3 1- koen
- Member
- 789 posts
- Joined: April 2020
- Offline
- hoknamahn
- Member
- 398 posts
- Joined: July 2005
- Offline
Hi koen,
It's a simple task for point clouds. All what you need is to open a point cloud in some position. First point in point cloud will be nearest point.
#pragma label pcfile “Point Cloud”
#pragma hint pcfile file
#pragma label radius “Radius”
#pragma hint nearest hidden
sop
nearestPoint(string pcfile = “”;
float radius = 1.0f;
export int nearest = -1)
{
int handle;
if(pcfile != “”) {
handle = pcopen(pcfile, “P”, P, radius, 1);
while (pciterate(handle))
{
pcimport(handle, “point.number”, nearest);
}
pcclose(handle);
}
}
It's a simple task for point clouds. All what you need is to open a point cloud in some position. First point in point cloud will be nearest point.
#pragma label pcfile “Point Cloud”
#pragma hint pcfile file
#pragma label radius “Radius”
#pragma hint nearest hidden
sop
nearestPoint(string pcfile = “”;
float radius = 1.0f;
export int nearest = -1)
{
int handle;
if(pcfile != “”) {
handle = pcopen(pcfile, “P”, P, radius, 1);
while (pciterate(handle))
{
pcimport(handle, “point.number”, nearest);
}
pcclose(handle);
}
}
f = conserve . diffuse . advect . add
fx td @ the mill
fx td @ the mill
- koen
- Member
- 789 posts
- Joined: April 2020
- Offline
I'll give that a try, thanks. It might be slow though since I have to call pcopen for every point on the mesh I want to move.
Also I can scatter a lot of points on the target mesh and use those points, but it would be perfect if it could work like the ray sop, where you get a position, even if there is no point there, it is just the closes point.
Thanks again for the tip!
Koen
Also I can scatter a lot of points on the target mesh and use those points, but it would be perfect if it could work like the ray sop, where you get a position, even if there is no point there, it is just the closes point.
Thanks again for the tip!
Koen
- hoknamahn
- Member
- 398 posts
- Joined: July 2005
- Offline
-
- Quick Links