Jump to content

create custom normal in VEX


Sebbe

Recommended Posts

Hi Sebbe. If you're trying to point the normal at the next point by point number, you can just use the Import Attribute VOP to import the point position of the current ptnum + 1.

If you need to point the normal at the nearest neighbor, you can either loop over all the points to see which one is closest to the current, or you can use the point cloud functions, open just 2 points, and find the further away of the 2 and import its point position.

Once you have the 2 points, making the vector between them is just a subtract.

Good luck dude.

Link to comment
Share on other sites

Tanx brianburke but this doesn´t work in my case.

i modefy the position in vex and direct after that in the same script i want to recomput the normal

based on the new position.

Exemple: i have a line and add a sinus function to the points, now i want the normals to point to the next point

i tried to put "P" in an array and lookup the previous index in the array and substract from it

but this just give me a zero value.

sop

sop2()

{

P.x=sin(P.y*10);

vector thePosition[];

int i;

for (i=0; i<Npt; i++)

{

thePosition = P;

N = thePosition - thePosition[i+1];

}

}

maybe the syntax is wrong here?! but it compiles fine.

any ide how to solve this?

tanx.

Edited by Sebbe
Link to comment
Share on other sites

Hi,

There is a Tangent SOP Digital Asset on the Exchange which does what you want. If you would like to create your own, I strongly recommend going through the VEX Help docs - Help menu > Houdini Help > VEX cookbook for simple examples and also the VEX language reference section.

Last but not least, your syntax is also wrong so check out the Help docs first. I believe there are other VEX files on the exchange which you can check out.

Good luck!

Cheers!

steven

Link to comment
Share on other sites

Tanx brianburke but this doesn´t work in my case.

Hi again Sebbe. You're right that it doesn't quite work because your doing the deformation and querying the deformed geometry in the same SOP. The easiest and most efficient way to get around this is to just use two SOPs, but you can still make it work in one SOP by deforming the geometry twice.

Here's what that looks like.

//this function does the deformation
//we define it externally so we can run it on the current point and the next point

vector docos(vector point)
{
point.y = cos(point.z);
return point;
}


sop alignnormals()
{
vector thatpoint;

//call the deforming function
vector thispoint = docos(P);

//get the point number of the next point
int thatptno = ptnum +1;

//import the undeformed point position of the next point
int yes = import("P", thatpoint, 0, thatptno);

//deform the next point
thatpoint = docos(thatpoint);

//build the normal from the deformed points
N = thispoint-thatpoint;

P = thispoint;
}

Link to comment
Share on other sites

Hi,

There is a Tangent SOP Digital Asset on the Exchange which does what you want. If you would like to create your own, I strongly recommend going through the VEX Help docs - Help menu > Houdini Help > VEX cookbook for simple examples and also the VEX language reference section.

Last but not least, your syntax is also wrong so check out the Help docs first. I believe there are other VEX files on the exchange which you can check out.

Good luck!

Cheers!

steven

The polyFrame SOP is great for getting tangents, I found it recently and looooove it :D

Link to comment
Share on other sites

You can use the Point SOP to create vectors that aim at the next point. Go to the Force Tab and turn on Add Edge Force. This creates two attributes. You want the edge_force attribute. This is by far the fastest way to generate these aim normals and automatically accounts for the last point look at nothing issue.

If you want to use this attribute referenced by name ($EDGE_DIRX, $EDGE_DIRY, $EDGE_DIRZ) then you have to append an Attribute Create SOP where:

Name: edge_dir

Local Variable: EDGE_DIR

Type: Vector

If you want this driven in to the normals, append a Point SOP. In the Normal field, use $EDGE_DIRX, $EDGE_DIRY, $EDGE_DIRZ.

----

The Tangent SOP can build real tangents at the points or the aim-at-next-point as well. The latter gives you normlal N or velocity v vectors along with the distance to the next point if you need it. It also has a different solution for the last-point-look-at-nothing issue.

Link to comment
Share on other sites

You can use the Point SOP to create vectors that aim at the next point. Go to the Force Tab and turn on Add Edge Force. This creates two attributes. You want the edge_force attribute. This is by far the fastest way to generate these aim normals and automatically accounts for the last point look at nothing issue.

I'm with sam.h ... for polygon curves, the PolyFrame SOP is really easy these days.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...