Tag Archives: VEX

Point Cloud in Houdini

Point cloud is an amazing feature in Houdini.
Below is a very basic example showing simplest use of point cloud using VEXpression.

Setup

point_clouds_101

VEX Code in PointWrangle SOP


float maxradius = 5;
vector nb_color;
float dist;

int handle = pcopen(@OpInput2, "P", @P, maxradius, 10);

while(pciterate(handle))
{
    pcimport(handle, "Cd", nb_color);
    pcimport(handle, "point.distance", dist);
    @Cd = lerp(@Cd, nb_color, dist/maxradius);
}

 

Alright, so let’s walk through the code.
First we declare all required variables.

float maxradius = 5;
vector nb_color;
float dist;

Then we use pcopen to “open” a point cloud.
Basically we are asking to retrieve 10 points from the geometry connected in 2nd input (@OpInput2) within maximum given radius near the position (@P) of currently being processed point (of geometry in 1st input).

int handle = pcopen(@OpInput2, "P", @P, maxradius, 10);

Now, we “iterate” through all the retrieved points.
This is similar to pseudo code : for(int i = 0; i < numpointsincloud; i++).
But Houdini provides pciterate which will iterate through all the points and will return false when all in the cloud are processed.

while(pciterate(handle))

Remember that VEX runs per-point (or per-prim…), so we are not iterating through the points of our main geometry but through the points from cloud around that point, lets call it main point.
Now we import whichever parameter we want from this cloud into local variables using pcimport.
In our case, we want the color (Cd) of the points and their distance from main point.

pcimport(handle, "Cd", nb_color);
pcimport(handle, "point.distance", dist);

And finally, we use imported data to alter attribute(s) of main point.

@Cd = lerp(@Cd, nb_color, dist/maxradius);

 

Result

point_clouds_result