Vex can be tricky to learn, especially for those who aren't used to writing code. While houdini's manual does include documentation on vex, the examples don't really show you the correct syntax or leave out information. For instance, look at the documentation for the ch vex function: ch(string channel). If you tried to write this code using the same format, it would not work. This is because strings in vex are supposed to be enclosed in ''. In my opinion, the documentation should be written including the proper syntax like this: ch('string channel'). This problem (in my opinion) makes it difficult to learn vex syntax from the documentation. Even now, the provided examples are confusing to me at times. I am writing this section on vex syntax as reference for me and to help others out there who are just getting started with vex. If anyone from sidefx happens to see this, please consider making the vex documentation a little less confusing : ) Another really great resource is tokeru.
I will be updating this page regularly, so it might be lacking content at first or I might re-organize after adding new content.
1. Vex makes it really easy to assign attributes to geometry and volumes and gives you both control and customization. Here is an example. Lets say you want to copy geometry to some points using the copy stamp SOP. You need a way to control the size of the copies. Add a attribute wrangle after the source points. The attribute we want to control is "pscale". In the attribute wrangle type in:
f@pscale = 0.5;
When you use an attribute like "pscale" we use the "@" before the attribute. In vex, you end code using a semi-colon. Ok, this is great. What if you don't want to type in values every time you want to make a change? No problem, just use the "ch" function. Type in:
f@pscale = ch('scale');
Now click the little icon to the right that looks like a slider and a "+" sign. This button will create a slider for you. If you wondering how I know to do this, I am just following the documentation. If you go to the vex documentation you'll notice a section on attributes and a section on functions. As I stated earlier, they show you an example that only partially follows the correct syntax.
2. As you use Houdini, you will notice the terms float, integer, and vector. Floats are simply numbers with decimal points (1.0). Integers are numbers without decimal points (1). A vector contains three values, like position and color. For example, you can set a point's position by using a vector:
v@P = ;
When you create an attribute, you should specify the type right before the “@”: “f” for float, “int” for integer, and “v” for vector. If you don’t specify this information, the wrangle can often guess what it is. However, it is better to specify this information because it doesn’t always guess correctly and you might receive some type of cast warning.
Here are some random findings :)
How to control instanced geometry with orient attribute: