VEX/EXPRESSIONS
Note: Lots of screen grabs i here that should be all turn into text when I have some time.
Some good links:
Some great tutorials done:
Houdini Hangout - 01/04 - The Joy of Vex (Days 1 & 2)
VEX for Algorithmic Design (1, 2, 3, 4,
UI
ALT-E: WILL OPEN THE code in a pop up window.
clicking on F1, over a vex function will open the doc of that function.
Ctrl-Enter to execute code
From entagma, VEX courses




Filtering and Deleting Geometry with Expressions
Substeps: Use
$Ffor frame and$FFfor substeps. Remember to include substeps if needed.Frame-Based Expressions:
Start Effect at Specific Frame:
$F > 150(Starts the effect at frame 150)Frame Range for Effect:
$F > 150 && $F < 280(Starts at frame 150 and ends at frame 280)Single Frame Effect:
$F == 1(Runs the effect for only frame 1)Interval-Based Effect:
$F % 15 == 1(Creates the effect every 15 frames)Start Earlier:
$F - 50(Starts the effect 50 frames earlier)
Color-Based Filtering:
Add to Group by Color:
@Cd.x > 0(In a group node, if the color red component is greater than 0, add to the group)Delete by Color:
@Cd.x == 0(Delete points where the color red component is zero)
Example: Udemy Course Example
Delete by Position:
@P.y > 0(Deletes points where the Y position is greater than 0)
Attribute Wrangle Examples
Displacement by Color:
@P.y = @Cd.x * -1;
This expression displaces the Y position of points based on the red component of the color attribute.
Color Addition:
@Cd += point(1, "Cd", @ptnum);
Adds color data from another point (from input 1) to the current point's color attribute.
Clamp Color:
@Cd = clamp(@Cd, 0, 1);
Ensures that the color values are clamped between 0 and 1.
Random Distance:
@dist = rand(@primnum);
Generates a random distance value based on the primitive number.
Displacement with Randomness:
@dist *= @Cd.x;
Multiplies the random distance by the red color component to introduce randomness in displacement.
Assign a name (can be done on particles groups and such through an attribwrangle:
s@name = 'aa';
if color is not zero, delete
@cd.x=00;
To multiply your value in a slider.
d *= ch('scale');

Velocity per point. (?)
Attribute Visualization and Conditional Coloring
Visualizing Attribute Transfer:
@Cd = set(@activated, 0, 0);
Sets the color attribute (@Cd) to visualize how the attribute transfer values affect the particles.
Conditional Coloring with Modulus:
if (@ptnum % 10) @Cd = {1,0,0}; else @Cd = {0,1,0};Uses the modulus operator to apply color based on the particle number (
@ptnum).@ptnum % 10calculates the remainder when dividing the particle number by 10.If there is a remainder (i.e., the particle number is not a multiple of 10), the color is set to red (
{1,0,0}).If there is no remainder (i.e., the particle number is a multiple of 10), the color is set to green (
{0,1,0}).
Example of all the UI parm you can create:
source: https://youtu.be/YKpqGx3TTps?list=PLzRzqTjuGIDhiXsP0hN3qBxAZ6lkVfGDI&t=617
popwrangle:
@inGroup += inpointgroup(0, "active", @ptnum);
We do the same thing in this pop wrangle that we did in the previous lecture to see which points are in the group so we can start moving those points that have been activated.

Building a Rope with Mass and Gravity
Assign Mass and Gravity:
Use the following VEX code to assign mass and gravity to points based on their group membership:
if (inpointgroup(0, "base", @ptnum)) @mass = 1; else @mass = 0; @pscale = 0.05;This code checks if a point is in the "base" group. If it is, the point gets a mass of
1. If it is not, the point gets a mass of0and thus will not be affected by gravity.Additionally, it sets the point scale (
@pscale) to0.05, which adjusts the size of the points.
If points have less than 2 neighbours. Meaning, find points and that are on the edge, at the corner and remove gravity for them.
if( len(neighbours(0, @ptnum)) <= 2 )
@mass = 0;
Make normal point inward
@pscale = 0.01;
v@v = @N * -1;
Emitting anywhere from frame 5 to frame 15.
Explanation:
This expression checks if the current frame number (
$F) is between 5 and 15, inclusive of 5 and exclusive of 16.It returns
truewhen the frame number is in that range, which can be useful for conditional operations that need to occur only within these frames.
$F >= 5 && $F < 16
Will create displacement using to color her and the normals.
@P += @Cd.x * @N;
Explanation:
This code modifies the position attribute (
@P) of each point.@Cd.xaccesses the red (x) component of the color attribute (@Cd), which is multiplied by the normal vector (@N) of each point.The result of this multiplication is then added to
@P, effectively moving each point along its normal direction by an amount influenced by the red color component.
-
allow us to randomly delete point using the slider.
@randVal = rand(@ptnum);
if( @randVal< ch("val" ) ) removepoint(0, @ptnum);

This is good if you have lines and you're trying to find the end of all the lines meaning there is no need for point Sur District will show you the point at the end of all of it.

Push velocity in Y

Good idea to create a slider instead of typing everytime to find a good value!

VEX
https://www.sidefx.com/docs/houdini/vex/snippets.html
VEX type Syntax | |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
examples: float, int, string, vector

will move all the point in x
source: https://youtu.be/V5i6KM_-8X0?list=PLzRzqTjuGIDhiXsP0hN3qBxAZ6lkVfGDI&t=1684

IIf you use specialize (ex of lit below) you don't have to write "p" before.
so you dont have to write =: v@p
@p will sufffice.
@p = rand(@p); It will make a random for each points

will set the color to red for each points

source: https://www.youtube.com/watch?v=O18pzht4uvk&list=PLzRzqTjuGIDhiXsP0hN3qBxAZ6lkVfGDI&index=3
Will choose the first only

All points

This will return on the int called "inbox" if the group called "box" is in it or not.
( You can see it in the attr editor)

This will return all the prim in the group "sphere" and multiply by 100 all those prim.

List all the prims in the group called "box"

get the nearest point of the object in the group sphere en rapport with the other object.

Move all points in Z. (Using top group instead of in code)

Use expressions directly in the group,
Points smaller than zera (negative) in X, roll the connad below.

Same but in a single command:

source: https://youtu.be/vLPhHCZA5kw?t=491
simple setup. Create a silder for Int and a slider for float.

Simple math:

Addding strings:

Generating randomness
source: https://entagma.com/courses/vex-101/1643-2/

test = test +1 will add 1 to your var.

DOing test = test +3 can be written quickly like: test +=3


source: https://entagma.com/courses/vex-101/vex101-pt-7-accessing-other-streams-attributes/
creating and pointing assets to a normal

Source: https://entagma.com/courses/vex-101/vex101-pt-8-generating-curl-noise/
Generating curl noise.

Make a group active or not.
if (@group_passive) i@active = 0;
else i@active = 1;
Different examples:
// Kill by Condition
dead = @id>chi('branch_limit')?1:0;
//give name
s@name = 'bb';
Functions:
While length(@P), measures the distance from the point to {0,0,0}, distance lets measure the distance from the point to another value you specif