Jump to content

Stuck on VEX Problem


Recommended Posts

I’m new to VEX but slowly getting the hang of it. This problem has me stuck, but I think I'm close..


My goal: deform a 3D grid along the Y axis to sit flush on top of a plane with animated point position noise. I’m later going to use the 3D grid as a point deformer to “stick” a more complicated mesh with secondary animations onto the deformed plane.


I have a solve that works but it’s kind of hacky: I have the plane with a mountain SOP set to Add, with a Min/Max of 0/1, so all of its points stay above 0 on the Y axis. Then to deform my 3D grid to it, I brought the plane in through an object merge, transformed the Y scale to -1 to invert it, then told every point on my 3D grid to find the distance to the plane geo, and use that distance as the Y position for each point.




Out of curiosity, I’m trying to solve it in a more elegant(?) way (without having to invert the plane).


My current approach: I’ve separated the points in the 3D grid into 2 different groups—one “floor” group (all points with a starting Y position of 0), then all the others in group “top”. Using the intersect() function, I’ve told the floor points to shoot a ray straight up on the Y axis and find the position it intersects with the plane, and then stored that position as an attribute named @hitPos.


The part I’m stuck on is adding the Y value of @hitPos to the @P.y of every point directly above it in the top group (the points with the same x and z pos). My first thought was to use a For loop on the top group, and use a function like findattribval() to search through the floor group for the point with the same x and z position, then add the @hitPos.y from the point it returns to the @P.y of the corresponding top points.




Then I figured out findattribval() won't work for this approach. Any idea how I can tell each point from the top group to look straight down, find the corresponding point on the floor group, and add the @hitPos.y attribute to its current @P.y?

Or if you have a smarter way to approach this altogether I'm all ears! Just trying to learn VEX :)

Link to comment
Share on other sites

In case anyone else comes across this, I figured it out.

Using the nearpoint function on the top points returned the point from the bottom group I needed to reference and grab the hitPos.y from

int refpoint = nearpoint(0, "floorPoints", @P);
@P.y += vector(point(0, "hitPos", refpoint)).y;

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.

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...