Why the difference between xyzdist in VEX versus Expressions

   7267   5   1
User Avatar
Member
228 posts
Joined: Dec. 2012
Offline
Does anyone know why the expression function xyzdist has a return_type argument that allows you to query UV values while the VEX equivalent does not?

I'm trying to loop through a collection of points scattered in space and get the interpolated UV value of the nearest spot on a mesh.

Thanks,
Kevin
www.kmcnamara.com
User Avatar
Member
1390 posts
Joined: July 2005
Offline
Common for VEX functions is to have multiply signatures (while in hscript this doesn't work):
http://www.sidefx.com/docs/houdini12.5/vex/functions/xyzdist [sidefx.com]
User Avatar
Member
228 posts
Joined: Dec. 2012
Offline
Hey, thanks for the reply.

I get that VEX functions can be overloaded, but there's no version with a return_type argument, so I can't get back UV values like I can with the expression function. Why the difference?

I have a random point in space and I want to get the closest UV value from a nearby mesh. Any idea how to do that?
www.kmcnamara.com
User Avatar
Member
696 posts
Joined: March 2009
Offline
You could ray SOP the point onto the geometry and attribute transfer the uv…
It can also be done in VOPs and probably faster.

Cheers
Toronto - ON
My Houdini playground [renderfarm.tumblr.com]
“As technology advances, the rendering time remains constant.”
User Avatar
Member
1390 posts
Joined: July 2005
Offline
KMcNamara
Hey, thanks for the reply.

I get that VEX functions can be overloaded, but there's no version with a return_type argument.

Second signature returns uvs and prim number in arguments (VEX's arguments are by reference in general):
float xyzdist(string geometry, vector pt, int &prim, vector &uv)

so (untested):


vector hitUV = 0;
int hitPrim = -1;
float dist = xyzdist(geometry, P, hitPrim, hitUV);

to get the distance, hit primitive number, and hit uv…
User Avatar
Member
228 posts
Joined: Dec. 2012
Offline
Ah, thanks guys. Got it working with both VOPSOP and Point Wrangle. My main problem was that my mesh was storing its UVs in barycentric coordinates, so I had to convert these to the actual UV space.

For example, my point wrangle code:

vector primUV = 0;
int hitPrim = -1;
xyzdist(@OpInput2, @P, hitPrim, primUV);

vector finalUV = 0;
prim_attribute(@OpInput2, finalUV, “uv”, hitPrim, primUV, primUV);

@uv = set(finalUV);
www.kmcnamara.com
  • Quick Links