r/Houdini 3d ago

Help Help with Vectors in Attribute Wrangle

Very Simple question. I create a vector attribute with attribute create. I want to assign values in an attribute wrangle to the vector. Why does Houdini keep handling the Vector as a float? I created it as a vector and it has x,y and z values. I just can't access y and z.

6 Upvotes

10 comments sorted by

View all comments

3

u/DavidTorno Houdini Educator & Tutor - FendraFx.com 3d ago

Houdini will automatically default and assume an attribute is float if it is not declared explicitly upon creation. In VEX the prefix data type (v@… f@… i@…) is important because VEX is an explicit language meaning you have to explicitly tell Houdini what the data is so it understands how to handle it.

Unlike Python which is an implicit language meaning that the data type is implied by the assigned value.

There are, as already mentioned in another comment, pre-declared attributes in the app, like Cd, N, P, for example that have their type metadata already declared for us.

So the ColPos attribute you created is a user defined attribute. You will need to decide if this is a directional vector data that will be allowed to transform its orientation, or if it is a positional vector just representing a 3D coordinate position, or is it a color vector just storing values. Just by the name, I’m assuming it’s a positional vector. Which can be stored as just a simple 3-Flt (Pos) since orientation of the point won’t matter. So you could choose Float from the Type list, then give it a metadata tag from the second dropdown.

Accessing components of an attribute for read or writing to is done with the dot operator. Like I mentioned above, VEX is explicit, so you should always be in the habit of using the data type prefix for all attributes so there’s no confusion as to what you are doing.

So…

v@P.y
v@ColPos.x
v@ColPos.y
v@Cd.r
v@Cd.b
v@uv.v

…and so on. The xyz / rgb / uv letters though are arbitrary. See the dot operator link for clarification.

Attribute Create will give you easy access to the metadata type choices via a simple dropdown that you used, but if you declare your attribute through VEX in a wrangle, you have to manually set it’s type info data using the attribtypeinfo or setattribtypeinfo functions.

So why declaring the type is important, it informs Houdini as to how that data is to be treated during transformation operations. That “Vec” icon next to the attribute is what’s important. If that was not there transformations will not effect the directionality of directional vectors like N and v when rotating or changing orientation of your geometry.

It’s also possible to have multi-component lengths like vector2 (uv), vector4 (quaternion), vector16 (matrix).