SamuZai
DavidKahlVFX
DavidKahlVFX

patreon


Quicktip #6 - VEX Geometry Functions

As many of you know I am a VEX enthusiast. A big reason for that is me being a programmer and most of it came very naturally to me. 

And that's why I am doing alot of content around making VEX more accesible. Not because it is the best tool but because it is a strong addition to the already strong SOP workflows.

One reason why using VEX seems so unpractical is that most have to have the documentation open while working in a wrangle. I often get asked why do I do it this way (using a wrangle with maybe 1-2 lines of code) when I could use e.g. three SOP nodes which would have the same effect.

And there is no general answer to that. Why do you use these 3 nodes instead of just typing 2 lines? Houdini doesn't care how you manipulate the data. It's just a matter of your preference.

I am way faster manipulating data with code - but that's only the case because I don't have to think about how the basic functions for geometry work. While working I only think "Now I need the position of that point and use the normal of that other point - and I just write the lines while I am thinking that.

And that's what I want to make more transparent this time. The red line that goes through alle the major functions. Once you see that pattern you will notice that you don't need the docs that often anymore until you don't need them at all.

So how can we look at it? Houdinis data is structured as you know in Points, Primitives, Verticies and Detail. And there is a variety of functions that allow you to access that data, manipulate it and write it back. 

You have your basic point() function to read point data and it's called like this

point(geometry,"attributename",pointnumber);

And this basic function has all the answers for you. Almost all functions start with the geometry source. Does it come from an input of the wrangle? Then the function starts with 0-3. Does it exist on a different node all together? Then type the path "../nodename".

This goes for all the data classes like primitive(), vertex() and detail(). 

After that point() wants the name of the attribute. And again that goes for all the functions. A function that is supposed to give you data - it needs the info from you where to find it. And if the function is supposed to find something, like findattribval you need to tell it what to find.

And also an important note. When there is a function for one data class - most of the time there is either a version for the other ones OR you can tell that function what to look for.

The last thing that point() needs is the pointnumber. And sure it is one of the more basic functions but you will notice that this is the way most of them function. 

1. Where does the data come from?

2. What data do you need?

3. When it could be on multiple elements - which is the right one?

Point, Primitive and Vertex can hold multiple elements and thats why you have to specify the number of the point, prim or vertex. When you use detail() you can see that this is not neccesary. With that in mind you can dissect every function. Take minpos() for example. It is supposed to give you the closest position on a geometry to a position you already know.

So according to the steps you provide the source and that known position. You don't expect anything else from it. 

minpos(0,position);

So here is a list of functions that are very useful and are an easy way to get yourself familiar with using VEX. (I keep it to the point versions )

point() 

setpointattrib()

addpoint()

intesect()

minpos()

nearpoint()

neighbour()

npoints()

rand()

fit()

I am going to stop here because I might just add all of them. Just take my word for it - being able to use these without thinking about it makes your life in Houdini alot easier even if you tend to keep it at SOPs, It still helps you alot to understand what is going on beneath the nodes.

Cheers

Dave



More Creators