How to check if piece is inside box bounds VEX

   3383   7   2
User Avatar
Member
5 posts
Joined: 2月 2022
Offline
Hi,

So I'm trying to tweak (art direct) a destruction simulation by going into the rbd bulletsolver and adding some forces.
I'm mainly using POP drag,POP dragspin and POP force. You can use VEXpressions to specify in my case where the force should be applied.
Currently I'm doing it manually like this, inside the popdrag VEXpression:
if(@P.x >= 523 && @P.x <= 539 &&
@P.y >= 40 && @P.y <= 43 &&
@P.z >= -187 && @P.z <= -181)
{
airresist = 10.0;
}
else
{
airresist = 0.001;
}

But I would like to make it easier to visualise and change. So I tried adding a box object and using the box bounds to check if a piece is inside the bounds of the box and add the force if it's the case. So I can visually see where the bounds are and change it easily, but I can't get a box in the dopnnet(or reference a box from the geometry level) and don't know how i would even define it in VEX.
Any seggestions on how I would do it?

Attachments:
solver.PNG (27.8 KB)
popdrag.PNG (92.7 KB)

User Avatar
スタッフ
411 posts
Joined: 2月 2008
Offline
The pop force DOP has an inputs tab where you can select a SOP as an input. From there you can use the getbbox VEX function to get the bounds of your cube.
User Avatar
Member
26 posts
Joined: 12月 2019
Offline
getbbox or volumesample should work
User Avatar
Member
5 posts
Joined: 2月 2022
Offline
npetit
The pop force DOP has an inputs tab where you can select a SOP as an input. From there you can use the getbbox VEX function to get the bounds of your cube.
ah thanks! I'll try that
Edited by EliasCyborn - 2022年8月26日 04:48:33
User Avatar
Member
5 posts
Joined: 2月 2022
Offline
akirasun_sh
getbbox or volumesample should work
thanks for your response!
Not sure how to actually code the if statement on how to compare each piece location to the bounds of the box that i get from that function. could you elaborate?
Or do i still just code it the same way like
if(P.x >= Bounds.xmin && P.Y <= Bounds.xmax && P.y >= ....)
or is there a faster way?
User Avatar
Member
53 posts
Joined: 2月 2017
Offline
EliasCyborn
akirasun_sh
getbbox or volumesample should work
thanks for your response!
Not sure how to actually code the if statement on how to compare each piece location to the bounds of the box that i get from that function. could you elaborate?
Or do i still just code it the same way like
if(P.x >= Bounds.xmin && P.Y <= Bounds.xmax && P.y >= ....)
or is there a faster way?

If you are using the bbox functions; getbbox_size() and getbbox_center() you could compare positions as you describe above, you just simply have to take into account the position of the box AND the scale. So @P.x > bboxcenter.x - (bboxsize.x / 2) and @P.x < bboxcenter.x + (bboxsize.x /2). However, the downside of this is that it is not very compact to write, and you can only use a box, preferably one without any rotations. Instead you can convert the box to a SDF with the VDB from polygons node in SOPS. You can then use volumesample() function to get the value of the SDF and if that is under 0, your point is inside of the box. This gives you more flexibility to use any arbitrary shape.

This great video might be able to clear up the whole topic; https://www.youtube.com/watch?v=QgzxBN1m9WE [www.youtube.com]

References to the functions;
https://www.sidefx.com/docs/houdini/vex/functions/getbbox_center.html [www.sidefx.com]
https://www.sidefx.com/docs/houdini/vex/functions/getbbox_size.html [www.sidefx.com]
https://www.sidefx.com/docs/houdini/vex/functions/volumesample.html [www.sidefx.com]
Edited by Robbert - 2022年8月26日 05:30:48
Technical VFX artist @ Housemarque / Sony Interactive Entertainment
User Avatar
Member
577 posts
Joined: 3月 2014
Offline
you can also use the windingNumber SOP to check if points are inside a geometry.
since packed geo is just "points" representing transforms of your pieces (plus collision hulls and a few other attributes and properties attached to them for RBD sims), you can then group those points (based on their winding number) and in DOPs simply apply your desired force to that group only.

hope this helps
Edited by fuat - 2022年8月27日 17:34:22
Fuat Yüksel
FX Supervisor | RISE Visual Effects Studios
User Avatar
Member
8785 posts
Joined: 7月 2007
Offline
use POP Group DOP (unless you really wanted to do it in VEX)
it has Bounding Option, where you can specify BBox, BSphere explicitly or BObject,BVolume and point to specific SOP
which in theory should cover all custom solution above

then either specify it in a Group parm of your POP nodes to limit their scope
or even use in VExpression if you want to control your values for in and out of group like in your screenshot
airresist = @group_MyGroup ? 10.0 : 0.001;
Edited by tamte - 2022年8月28日 05:16:07
Tomas Slancik
FX Supervisor
Method Studios, NY
  • Quick Links