📅  最后修改于: 2023-12-03 15:31:09.236000             🧑  作者: Mango
Houdini VEX is a C-like programming language that allows you to create custom nodes and manipulate points, primitives, and attributes in your geometry. One of the most common tasks in Houdini is to loop over points, and in this tutorial, we will explore how to do that using VEX.
Before we start coding, let’s create a simple geometry to work with. In Houdini, you can create a box by going to the top menu and selecting Create > Geometry > Box
. Once you have created the box, select it and press the Tab
key to open the Tab Menu
. From there, select Add Node > VEX
.
Now that we have our VEX node, let’s write some code. To loop over points, we need to use the foreach
loop. The syntax for the foreach
loop is as follows:
foreach (int i; @ptnum[]) {
// Code to be executed for each point
}
The foreach
loop will loop over each point in the geometry, and the i
variable will hold the index value of the current point. Inside the loop, we can use the i
variable to access the attributes of the current point. For example, to get the position of the current point, we can use the point()
function:
vector pos = point(0, "P", i);
This line of code will retrieve the position of the current point in the P
attribute.
Let’s say we want to scale the points of the box by a factor of 2
. We can achieve this by multiplying the position of each point by 2
. Here’s the full code:
foreach (int i; @ptnum[]) {
vector pos = point(0, "P", i);
pos *= 2.0;
setpointattrib(0, "P", i, pos);
}
This code will loop over each point in the geometry, get its position, multiply it by 2
, and set the new position back into the P
attribute.
In this tutorial, we learned how to loop over points in Houdini using VEX. We explored the foreach
loop and how to access the attributes of each point using the point()
function. We also learned how to modify the position of points and update their attributes using the setpointattrib()
function. With this knowledge, you can start creating custom nodes and manipulating geometry in Houdini. Happy coding!