# How to make the pointreplicate follow the shape of the mesh

## Recommended Posts

Hi guys I need help to make the points follow the shape of a mesh or position of the mesh. thanks in advance

##### Share on other sites

Why don't you reproject these points onto the mesh ?

First solution, projecting points onto the closest surface : take a Point Wrangle, plug the points on first input and the mesh on the second input, and add the code :

vector pos = minpos(1, @P);

@P = pos;

Otherwise, you can also project each point onto the geometry along the vertical direction using intersect() function, but you will have to write a bit more code, because you need to cast ray upward or downward depending if your points are above or below ground. Just check what intersect returns : if it is -1, then it found no intersection, and you have to cast a ray in the reverse direction ({0,1,0} or {0,-1,0} : up or down).

Edited by StepbyStepVFX

##### Share on other sites
1 hour ago, StepbyStepVFX said:

Why don't you reproject these points onto the mesh ?

First solution, projecting points onto the closest surface : take a Point Wrangle, plug the points on first input and the mesh on the second input, and add the code :

vector pos = minpos(1, @P);

@P = pos;

Otherwise, you can also project each point onto the geometry along the vertical direction using intersect() function, but you will have to write a bit more code, because you need to cast ray upward or downward depending if your points are above or below ground. Just check what intersect returns : if it is -1, then it found no intersection, and you have to cast a ray in the reverse direction ({0,1,0} or {0,-1,0} : up or down).

THANK YOU SO MUCH StepbyStepVFX i did your first solution and it works.. vector pos = minpos(1, @P); can you explain this to me if thats okay. thanks again

can you help me again to make rotation base on the normal of the mesh thanks

Edited by awie12

##### Share on other sites

If you want to learn VEX code, your best friend will be the documentation page of VEX functions in Houdini : https://www.sidefx.com/docs/houdini/vex/functions/minpos.html

I don't know if you are fluent in any programming language (VEX is similar to C), but a function is a piece of code you can call, giving it some parameters, and it returns to you a result. In any language, your data is limited to certain types : in VEX, you will have integers, float, vectors etc. and arrays of above mentionned types. The result of a function is always of one of the types above (this is called the signature of the function).

Reading the doc you see that minpos() returns the closest position from another position on a surface, therefore it returns a data of type "vector" (position is made of three floats, which is a vector). For that it takes at least 2 parameters : the first is the geometry stream you are looking at (0 for geo plugged on the first input of your Point Wrangle, 1 for the second etc.), and the second one is a position in space (a vector). Here we search for the closest surface position of the current point : its position is "@P".

So I just create a local variable called "pos" like position and says it is equal to what the minpos() function returns when I give it the parameters 1 and @P .

I could have declared my variable alone, and then store the result of minpos() function in it, it would have worked the same :

vector pos;

pos = minpos(1,@P);

@P = pos;

Hope that's clear ;-)

Edited by StepbyStepVFX

##### Share on other sites
8 minutes ago, StepbyStepVFX said:

If you want to learn VEX code, your best friend will be the documentation page of VEX functions in Houdini : https://www.sidefx.com/docs/houdini/vex/functions/minpos.html

I don't know if you are fluent in any programming language (VEX is similar to C), but a function is a piece of code you can call, giving it some parameters, and it returns to you a result. In any language, your data is limited to certain types : in VEX, you will have integers, float, vectors etc. and arrays of above mentionned types. The result of a function is always of one of the types above (this is called the signature of the function).

Reading the doc you see that minpos() returns the closest position of another position on a surface, therefore it returns a data of type "vector" (position is made of three floats, which is a vector). For that it takes at least 2 parameters : the first is the geometry stream you are looking at (0 for geo plugged on the first input of your Point Wrangle, 1 for the second etc.), and the second one is a position in space (a vector). Here we search for the closest surface position of the current point : its position is "@P".

So I just create a local variable called "pos" like position and says it is equal to what the minpos() function returns when I give it the parameters 1 and @P .

I could have declared my variable alone, and then store the result of minpos() function in it, it would have worked the same :

vector pos;

pos = minpos(1,@P);

@P = pos;

Hope that's clear ;-)

Thanks a lot man. I will read the documents about vex function. have a nice day cheers.

##### Share on other sites
On 10/15/2019 at 2:06 PM, StepbyStepVFX said:

If you want to learn VEX code, your best friend will be the documentation page of VEX functions in Houdini : https://www.sidefx.com/docs/houdini/vex/functions/minpos.html

I don't know if you are fluent in any programming language (VEX is similar to C), but a function is a piece of code you can call, giving it some parameters, and it returns to you a result. In any language, your data is limited to certain types : in VEX, you will have integers, float, vectors etc. and arrays of above mentionned types. The result of a function is always of one of the types above (this is called the signature of the function).

Reading the doc you see that minpos() returns the closest position from another position on a surface, therefore it returns a data of type "vector" (position is made of three floats, which is a vector). For that it takes at least 2 parameters : the first is the geometry stream you are looking at (0 for geo plugged on the first input of your Point Wrangle, 1 for the second etc.), and the second one is a position in space (a vector). Here we search for the closest surface position of the current point : its position is "@P".

So I just create a local variable called "pos" like position and says it is equal to what the minpos() function returns when I give it the parameters 1 and @P .

I could have declared my variable alone, and then store the result of minpos() function in it, it would have worked the same :

vector pos;

pos = minpos(1,@P);

@P = pos;

Hope that's clear ;-)

Hi man can i ask how to make the point faces to the normal of the mesh

Edited by awie12

##### Share on other sites

What do you mean ?

I understand you projected points on a mesh (a terrain probably ?) and now you want the points to inherit the normals from the faces of the mesh on which they landed after projection, correct ? (you probably want to instance tress on these points, and you want them to be oriented with the normal of the terrain ?).

If so, take a point wrangle, plug the points on the first input, put the terrain/mesh (who should have a normal attribute, otherwise it won't work), and write :

int crossprim;

vector crossuv;

int dist = xyzdist(1, @P, crossprim, crossuv);

@N = primuv(1, "N", crossprim, crossuv);

• 1

##### Share on other sites
17 minutes ago, StepbyStepVFX said:

What do you mean ?

I understand you projected points on a mesh (a terrain probably ?) and now you want the points to inherit the normals from the faces of the mesh on which they landed after projection, correct ? (you probably want to instance tress on these points, and you want them to be oriented with the normal of the terrain ?).

If so, take a point wrangle, plug the points on the first input, put the terrain/mesh (who should have a normal attribute, otherwise it won't work), and write :

int crossprim;

vector crossuv;

int dist = xyzdist(1, @P, crossprim, crossuv);

@N = primuv(1, "N", crossprim, crossuv);

sorry for my bad explanation. yes i want to instance a leaves or trees on the points and oriented them with the normal of the terrain. sorry for the trouble man I am really new to houdini. I uploaded the file can you check if my nodes  are in the right position or somethings missing. thanks a lot

Parking_Leaves2.hip

Camera_TreesV3.abc

##### Share on other sites
2 hours ago, StepbyStepVFX said:

What do you mean ?

I understand you projected points on a mesh (a terrain probably ?) and now you want the points to inherit the normals from the faces of the mesh on which they landed after projection, correct ? (you probably want to instance tress on these points, and you want them to be oriented with the normal of the terrain ?).

If so, take a point wrangle, plug the points on the first input, put the terrain/mesh (who should have a normal attribute, otherwise it won't work), and write :

int crossprim;

vector crossuv;

int dist = xyzdist(1, @P, crossprim, crossuv);

@N = primuv(1, "N", crossprim, crossuv);

Thanks again Step I already got it. My brain is not working awhile ago haha but now I already got it thank you step cheers.

Edited by awie12

##### Share on other sites
On 10/17/2019 at 1:08 PM, StepbyStepVFX said:

What do you mean ?

I understand you projected points on a mesh (a terrain probably ?) and now you want the points to inherit the normals from the faces of the mesh on which they landed after projection, correct ? (you probably want to instance tress on these points, and you want them to be oriented with the normal of the terrain ?).

If so, take a point wrangle, plug the points on the first input, put the terrain/mesh (who should have a normal attribute, otherwise it won't work), and write :

int crossprim;

vector crossuv;

int dist = xyzdist(1, @P, crossprim, crossuv);

@N = primuv(1, "N", crossprim, crossuv);

All the powerfull and magic of houdini, few line written to do what other software will do with addon or more hassle, and with less flexibility.

If you are confused and intimidate but these vex lines, i could tell you that if you start learning houdini in a proper way from the base, this will look totally natural to you very quickly in fact

## Create an account

Register a new account