Jump to content

Acquire and change UV coordinates for a primitive?


Atom

Recommended Posts

Hi All,

 

I am looking for a way to use a python node to fetch the UV coordinates for a given Primitive. I can get the uv attribute but I m not sure how to gain access to the coordinates.

 

Does anyone have any tips or examples?

 

Thanks

post-12295-0-29238100-1428943886_thumb.j

Edited by Atom
Link to comment
Share on other sites

You mean uvs of the vertices' primitive?

for prim in geo.prims():
    for vertex in prim.vertices():
        coord = vertex.attribValue("uv")
        vertex.setAttribValue("uv", hou.Vector3(coord) * 0.5)
 
Link to comment
Share on other sites

Thank you, I think that will do it. Your above example scales all UV coordinates in half.

 

So I am still a bit unclear about the return values from Houdini functions.

 

 

coord = vertex.attribValue("uv")

The return value, coord is a tuple, I think. Is that why you need to convert explicitly to a Vector3 on the next line?

When fetching attribValues is it expected to test for type of return value before assuming the variable contents?

Edited by Atom
Link to comment
Share on other sites

I didn't check it, but since tuple is immutable I assumed that I can't do algebra on it, but hou.Vector3 will handle it.

 

When it comes to return values in general, I think that idea was to make hou modue as fast as possible without making it annoying at the same time. So, if I'm not mistaken, many if not most attributes' functions return tuples, because this is the most efficient way of dealing with conversion from C++ to Python types. There are even more bizarre things like returning all attribute values in byte string which is good for efficiency when you pipe this data further to c++/numerical modules (like numpy). 

 

On the other side, linear algebra stuff (matrices, transforms, space conversions etc), returns native hou types, since they don't usually compute a lot - so conversion cost isn't that much. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...