Jump to content

Transform Position Y of an object from Ocean Waves while it is animated to move through the surface of Ocean via Vex


Recommended Posts

Hi,

I am fairly new to houdini. I have attached a scene here, I have animated a box to move through the Ocean Wave in X direction and I want it to follow the Y transformation of the point from the ocean wave so that it looks like it is interacting with the wave below. I want a VEX method please.

My file picks up the transformation of a single point but it does not updates the points while the box moves so the Y transform remains intact with the first point that it picks up at the beginning. So please look at the attached file and please let me know how to overcome it.

And please if anyone can suggest me a good source to learn VEX language for houdini from the beginning. And I know python language so will I have to learn Hscript or Python is a perfect substitute?

box_move.hip

Link to comment
Share on other sites

int handle = pcopen(1, "P", @P, 2, 10);
vector value = pcfilter(handle, "P");
@P.y += value.y;

 

*Very* crude method :D Perform a point cloud lookup to find the nearest 10 points from the box, searching radius of 2 units (no idea what would work best I just chucked those in). Obviously won't include things like velocity (falling faster down the waves, slower up, etc) but somewhere to get you started. One you have the average information for the wave movement you can do more intelligent things than just directly adding it to the box position. 

  • Like 1
Link to comment
Share on other sites

17 hours ago, adrianr said:

int handle = pcopen(1, "P", @P, 2, 10);
vector value = pcfilter(handle, "P");
@P.y += value.y;

 

*Very* crude method :D Perform a point cloud lookup to find the nearest 10 points from the box, searching radius of 2 units (no idea what would work best I just chucked those in). Obviously won't include things like velocity (falling faster down the waves, slower up, etc) but somewhere to get you started. One you have the average information for the wave movement you can do more intelligent things than just directly adding it to the box position. 

Your code worked like charm, thanks a lot.

But I am really confused as to what was wrong in my code? I have written my code below. My code somewhat works but the box/boat jumps weirdly from random points into  Y Position. Please help

f@near = nearpoint("op:../ocean_preview", @P);

v@p = point(1, "P", @near);

@P.y += @p[1];

 

And Please suggest me some good source for leaning vex.

Link to comment
Share on other sites

nearpoint function returns an integer. so this line would be i@near = nearpoint("op:../ocean_preview", @P);
then I'm not sure bout that op../oceanpreview. I always use the inputs 0 to 3 but as the help docs state, you can use it but with full path to node.

second line is correct.
what do you want to achieve with >@p[1]< ? access the y-component? if so, the syntax is @p.y (@P.y += @p.y)
[see how P and p is somewhat confusing? might be an easy typo and later you wonder why your result isnt correct. what i want to say is use meaningful names. in this case something like nearpos instead of p]

 

edit: i learned vex with the help docs. and still use the docs whenever i use vex: http://www.sidefx.com/docs/houdini15.0/vex/functions/_index


just think of what you want to achieve, and what you need to do it and enter a search term
but there are also some tutorials out there, paid and free. just have a look at youtube, google

Edited by 3dome
Link to comment
Share on other sites

14 minutes ago, 3dome said:

nearpoint function returns an integer. so this line would be i@near = nearpoint("op:../ocean_preview", @P);
then I'm not sure bout that op../oceanpreview. I always use the inputs 0 to 3 but as the help docs state, you can use it but with full path to node.

second line is correct.
what do you want to achieve with >@p[1]< ? access the y-component? if so, the syntax is @p.y (@P.y += @p.y)
[see how P and p is somewhat confusing? might be an easy typo and later you wonder why your result isnt correct. what i want to say is use meaningful names. in this case something like nearpos instead of p]

 

edit: i learned vex with the help docs. and still use the docs whenever i use vex: http://www.sidefx.com/docs/houdini15.0/vex/functions/_index


just think of what you want to achieve, and what you need to do it and enter a search term
but there are also some tutorials out there, paid and free. just have a look at youtube, google

Hi, Thanks a lot. I was testing this code so I did not name it properly, but ya, I must always name it properly.

And Even after converting it into integer, as u suggested, i@near. 

The box still jitters a lot. While the code suggested by @adrianr works like charm, in his case, the box moves without any jitter and smooth translation.

Please help.

Link to comment
Share on other sites

One more thing. Any way to get any rotation data too?

When I use the copy node to copy a large boat over a single point, in many places the boat seems to float because it refers only one point. It would be great if the boat could follow the curves of the waves and orient it accordingly.

And also as @adrianr posted earlier, how can I get the data so that the boat falls down the waves quicker than it gets lifted by the waves.

Capture.PNG

Capture2.PNG

Edited by cgartashish
Uploaded Snapshot of scene.
Link to comment
Share on other sites

well, the point cloud method averages the P attribs of all the found points (-> smooth) while your code does not


i'm at work right now ..maybe ill have a closer look at it tonight

 

i remember seeing a fxphd tutorial about a ship floating through stormy ocean and in that video he instructor showed a method for all your problems, like up and down motion and so on. iirc it wasnt vex based but anyway, look for that tutorial it will answer all your questions ;)

  • Like 1
Link to comment
Share on other sites

5 hours ago, cgartashish said:

Your code worked like charm, thanks a lot.

But I am really confused as to what was wrong in my code? I have written my code below. My code somewhat works but the box/boat jumps weirdly from random points into  Y Position. Please help

f@near = nearpoint("op:../ocean_preview", @P);

v@p = point(1, "P", @near);

@P.y += @p[1];

 

And Please suggest me some good source for leaning vex.

With the code I posted just be sure to amend the last line to " @P.y = value.y; " as per Kardonns suggestion. There's no need to add it to the existing P, you may as well just replace it. I think I left it in there as that's what was in your original code so maybe that's what you were after. 

Regarding the issue with using nearpoint and jitter I'm guessing it's just a case of not enough sampled points. Nearpoint returns just that, the nearest point. That means once you've got the position of that point, your box is going to match the position of that point perfectly until it finds a new nearest point, it's then going to jump. There won't be any nice interpolation, it will just find a new point and bang, off it goes. The other issue is that you're only looking from a point in the middle of the box, because it's packed geo. So depending on which way you're looking at it, and how detailed the waves are, the middle of the box could be responding to ripples and surface movements you can't see, which would make it look like it was jumping. 

The point cloud gets around this by averaging the position of the nearest ten points. You could sample even more points, but eventually you will loose the accuracy of the local motion. 

First suggestion for VEX would be http://www.tokeru.com/cgwiki/index.php?title=HoudiniVex - Frankly one of the most helpful Houdini resources on the internet. Run through the whole page from top to bottom and you'll learn a ton. Shaun Lipowski's CG Society course is also very good. 

Edited by adrianr
  • Like 1
Link to comment
Share on other sites

35 minutes ago, 3dome said:

well, the point cloud method averages the P attribs of all the found points (-> smooth) while your code does not


i'm at work right now ..maybe ill have a closer look at it tonight

 

i remember seeing a fxphd tutorial about a ship floating through stormy ocean and in that video he instructor showed a method for all your problems, like up and down motion and so on. iirc it wasnt vex based but anyway, look for that tutorial it will answer all your questions ;)

Wow..you guys are awesome. So prompt replies..Thanks a ton guys for your help.

And @3dome thanks about the smooth method explanation, It is so much clear now. One more thing, I am fluent in python so can all the functions in vex be replaced by python or should I learn VEX thoroughly? and any tutorial for python, specially for the python node equivalent to wrangler node?

 

Thanks again.

Link to comment
Share on other sites

i dont have that much knowledge about python unfortunately. i don't think its possible to use vex functions in python but I could be completely wrong here! I can just recommend you to learn VEX, since it's the core of most advanced custom fx setups.
VEX is meant to directly work on geometry whereas python is more like a universal API to create pipeline tools and such things. I rarely see python nodes in fx node-trees.

  • Like 1
Link to comment
Share on other sites

Hey all, figured I'd just chime in again quick cause if you really want to get straight up proper with this solve, you'd want to do this.

vector p;
vector hitprimuvw;

int test = intersect(1, @P, {0,-1000,0}, p, hitprimuvw);
if (test <= 0) {intersect(1, @P, {0,1000,0}, p, hitprimuvw);}

v@P = p;

Quick explanation of the code...check what the position is of Input1 directly under Input0 (0, -1000, 0). If that comes back nil, check what the position is of Input1 direction above Input0 (0, 1000, 0). After you've done that, simply set @P to that position.

I use 1000 instead of 1 because intersect uses the vector's length, and so if your boat was more than 1 unit above or below the ocean here, the code wouldn't work.

This is going to be the most bulletproof solve because it's not relying on point data. The Point Cloud solution is nice because it's at least averaging out the points and then that result is much closer to accurate, but still not 100%. Near Point is going to be a VERY jittery solution because the nearest point to the boat is going to be constantly moving around in X, Y, Z with an ocean surface...and then even worse, snapping to new points on the ocean surface as they pass the threshold of becoming the new nearest point.

The Intersect based solution I posted here doesn't rely on points; it's going to intersect with the precise primitive and primitiveuvw @P data from a direct line underneath your boat. 

This all being said...at the end of the day it's a boat, and you probably would end up going with a Point Cloud solve since boats definitely would average out their position and rotation with all the water they're in contact with. What you'd do is use the position generated from this intersect VEX code though, and lookup the Point Cloud from there in a 2 step process.

1) Find the point on the ocean straight below/above the boat.

2) Average out the data around that point using PC Filtering.

3) Apply the @P and @N attributes to your point and attach your boat to that.

 

intersect_vex_solve_v001.hip

Edited by Kardonn
  • Like 2
Link to comment
Share on other sites

15 hours ago, Kardonn said:

Hey all, figured I'd just chime in again quick cause if you really want to get straight up proper with this solve, you'd want to do this.


vector p;
vector hitprimuvw;

int test = intersect(1, @P, {0,-1000,0}, p, hitprimuvw);
if (test <= 0) {intersect(1, @P, {0,1000,0}, p, hitprimuvw);}

v@P = p;

Quick explanation of the code...check what the position is of Input1 directly under Input0 (0, -1000, 0). If that comes back nil, check what the position is of Input1 direction above Input0 (0, 1000, 0). After you've done that, simply set @P to that position.

I use 1000 instead of 1 because intersect uses the vector's length, and so if your boat was more than 1 unit above or below the ocean here, the code wouldn't work.

This is going to be the most bulletproof solve because it's not relying on point data. The Point Cloud solution is nice because it's at least averaging out the points and then that result is much closer to accurate, but still not 100%. Near Point is going to be a VERY jittery solution because the nearest point to the boat is going to be constantly moving around in X, Y, Z with an ocean surface...and then even worse, snapping to new points on the ocean surface as they pass the threshold of becoming the new nearest point.

The Intersect based solution I posted here doesn't rely on points; it's going to intersect with the precise primitive and primitiveuvw @P data from a direct line underneath your boat. 

This all being said...at the end of the day it's a boat, and you probably would end up going with a Point Cloud solve since boats definitely would average out their position and rotation with all the water they're in contact with. What you'd do is use the position generated from this intersect VEX code though, and lookup the Point Cloud from there in a 2 step process.

1) Find the point on the ocean straight below/above the boat.

2) Average out the data around that point using PC Filtering.

3) Apply the @P and @N attributes to your point and attach your boat to that.

 

intersect_vex_solve_v001.hip

Hi, Thanks again, this method is similar to a vop example I saw once, Please can you explain the " int test =  (1, @P, {0, -1000, p, hitprimuvw); "

You have explained it but i did not really get it, I am really new to all this concepts. You all have been so helpful, I am keen to learn this method and understand the math that houdini actually does.

Link to comment
Share on other sites

On 7/21/2016 at 10:33 PM, adrianr said:

int handle = pcopen(1, "P", @P, 2, 10);
vector value = pcfilter(handle, "P");
@P.y += value.y;

 

*Very* crude method :D Perform a point cloud lookup to find the nearest 10 points from the box, searching radius of 2 units (no idea what would work best I just chucked those in). Obviously won't include things like velocity (falling faster down the waves, slower up, etc) but somewhere to get you started. One you have the average information for the wave movement you can do more intelligent things than just directly adding it to the box position. 

Hi, if I replace int handle with i@handle, the code does not work and shows an error. I am unable to find an answer, why?. Same goes with vector value, if I replace it by v@value.

And Please can you explain the math behind 'pcopen' and 'pcfilter'? 'pcopen' is bit simple and I have a little idea of what happens under the hood. But how does 'pcfilter' works? Even houdini help doc does not explains it well. Please help.

Link to comment
Share on other sites

10 hours ago, cgartashish said:

Hi, Thanks again, this method is similar to a vop example I saw once, Please can you explain the " int test =  (1, @P, {0, -1000, p, hitprimuvw); "

You have explained it but i did not really get it, I am really new to all this concepts. You all have been so helpful, I am keen to learn this method and understand the math that houdini actually does.

Have a look at the documentation for that intersect function:

"int intersect(int input, vector orig, vector dir, vector p&, vector uvw&) | This function computes the intersection of the specified ray with the geometry. The primitive number is returned, or -1 if there is an error or no intersection found."

When you see things like int, float, vector, matrix, etc., before a function, it means some piece of data is going to be written out when the function runs...in this case, "the primitive number is returned" aka the number of the polygon face hit by the intersect. If that's < 0, then the intersect didn't hit any polygons.

And when you see things like "vector p&", the "&" means that when the function runs, it's going to modify that specific variable you're feeding in.

For my intersect example, I'm initializing two variables before I run the function; "vector p" and "vector hitprimuvw". These are completely default vectors, and when they're used in the "vector p&, vector uvw&" part of the intersect function, they will get new data written to them. In this case after intersect runs, vector p becomes the world position of where the intersection took place, and vector hitprimuvw becomes the parametric coordinate of the primitive that was hit.

Functions like intersect, xyzdist, primuv, they're definitely more advanced VEX functions and they do hinge upon having a pretty solid understanding of how VEX interacts with data and variables. It's the kind of thing that just starts clicking more and more the more you do them.

  • Like 1
Link to comment
Share on other sites

53 minutes ago, Kardonn said:

Have a look at the documentation for that intersect function:

"int intersect(int input, vector orig, vector dir, vector p&, vector uvw&) | This function computes the intersection of the specified ray with the geometry. The primitive number is returned, or -1 if there is an error or no intersection found."

When you see things like int, float, vector, matrix, etc., before a function, it means some piece of data is going to be written out when the function runs...in this case, "the primitive number is returned" aka the number of the polygon face hit by the intersect. If that's < 0, then the intersect didn't hit any polygons.

And when you see things like "vector p&", the "&" means that when the function runs, it's going to modify that specific variable you're feeding in.

For my intersect example, I'm initializing two variables before I run the function; "vector p" and "vector hitprimuvw". These are completely default vectors, and when they're used in the "vector p&, vector uvw&" part of the intersect function, they will get new data written to them. In this case after intersect runs, vector p becomes the world position of where the intersection took place, and vector hitprimuvw becomes the parametric coordinate of the primitive that was hit.

Functions like intersect, xyzdist, primuv, they're definitely more advanced VEX functions and they do hinge upon having a pretty solid understanding of how VEX interacts with data and variables. It's the kind of thing that just starts clicking more and more the more you do them.

Thank you for such detailed description, really appreciate the time you are giving me. On last thing though, I went through the houdini help docs as you suggested. Please can you explain me why did you use -1000 in the function as your vector dir? How to guess those numbers? or what maths to perform? This is almost the last piece of the puzzle. Please help.

Thanks again. :)

Link to comment
Share on other sites

Ah yeah, so the intersect function just checks for intersections along the vector you give it, until it runs out of vector at which point it just stops and returns nothing. If I left it as your standard {0, -1, 0} then if the boat was more than 1 unit away from the water, the intersect would fail.

There's no option in the intersection function to have unlimited distance, so I just give it some big number way bigger than I'd ever expect to need.

  • Like 1
Link to comment
Share on other sites

7 minutes ago, Kardonn said:

Ah yeah, so the intersect function just checks for intersections along the vector you give it, until it runs out of vector at which point it just stops and returns nothing. If I left it as your standard {0, -1, 0} then if the boat was more than 1 unit away from the water, the intersect would fail.

There's no option in the intersection function to have unlimited distance, so I just give it some big number way bigger than I'd ever expect to need.

Thanks alot..great..now finally problem solved :) . I will post again if I am again and will also post my WIPs. Tc..

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