Copy 1st value of vertex array attribute to a point float

   480   5   2
User Avatar
Member
39 posts
Joined: Oct. 2011
Offline
I've got a uv attribute on the vertices of my object. I need to copy the first value of the uv array to a float attribute on the corresponding point. I'm currently doing it by first promoting the uv attribute from the vertices to points and then doing the copy operation in a wrangle. However, I'd like to cut out that one promote operation by using the wrangle to just directly copy the first value of the uv attribute as it exists on the vertex, over to the target point attribute. I just can't figure out the code. If you can help, please do.
User Avatar
Member
101 posts
Joined: Dec. 2019
Offline
In a point wrangle you can extract the uv attribute from the corresponding vertex in this way :

vector uv = vertex(0, "uv", @vtxnum);
f@u = uv.x;

vertex() function reads attribute data from a given vertex number of the geometry, and @vtxnum evaluates to a vertex number thats wires to the point being looped over in the wrangle
Houdini Pipeline Supervisor @ TAT Studio
User Avatar
Member
39 posts
Joined: Oct. 2011
Offline
Thanks for that. I wonder though - is there a way to do it that doesn't involve reading all three x,y,z entries of the array? I'm trying to make this as efficient as I can and it seems that if I could just directly copy the x entry into the point attribute, that would be ideal. Conceptually, I'm thinking of something like this (but that works):
f@u = vertex(0, "uv"[0], @vtxnum);
Edited by fbb - April 5, 2024 09:44:46
User Avatar
Member
101 posts
Joined: Dec. 2019
Offline
When the return type of the called function is vector (for example minpos), then you can use this syntaxe to extract the desired component without having to store a new variable :

f@x = minpos(1, v@P).x;
f@y = minpos(1, v@P)[1];

But when the function has more possibilities of return type, like the vertex/prim/point functions, then you have to cast the return type to a vector to be able to use this kind of syntaxe :

f@u = vector(vertex(0, "uv", @vtxnum))[0];
f@v = vector(vertex(0, "uv", @vtxnum)).y;
Houdini Pipeline Supervisor @ TAT Studio
User Avatar
Member
8579 posts
Joined: July 2007
Offline
this should also work, since even float signature can read vector attribute, in which case it will return only the first component
f@u = vertex(0, "uv", @vtxnum);
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
39 posts
Joined: Oct. 2011
Offline
Thank you so much guys!
  • Quick Links