Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  How to query Obi geometry with raycasts?
#11
(28-05-2021, 10:24 PM)Hatchling Wrote: For a raycast, I know you can approximate a point of impact by getting the closest point between the ray and a simplex. For example, you could get the closest point between a ray and line segment, and if the distance is less than the thickness of the ray + the thickness of the line segment, it is a hit, and the closest point on the ray is the hit point. But this isn't accurate; it shouldn't be the point of deepest penetration, but of first penetration, which requires a bit more weird math to compute. Are you using the approximate or exact method (or some other method) to calculate the hit point?

Short answer: Exact method.

Long answer: Simplex collisions use an iterative method (Frank-Wolfe convex optimization) to calculate distances/intersections of any convex shape with a simplex, which might be made of particles of different radius. In case of rays: for each iteration, it calculates the intersection between the ray and a sphere centered at the current barycentric coordinates in the simplex (sphere radius is interpolated from the radii at the simplex vertices). If there's no intersection, it calculates the distance between the ray and the sphere. Over a few iterations (8 by default, up to 32, exposed in the solver as a parameter) this converges to the exact solution: a point in the surface of the simplex where the ray first intersects it, or the closest point between the ray and the simplex otherwise.

For 0-simplices (particles), this gives the exact solution in just one iteration as it reduces to a sphere/ray intersection test, or a point-ray distance test if the intersection fails.

(28-05-2021, 10:24 PM)Hatchling Wrote: Also, I'm guessing the Bresenham algorithm is a way to enumerate through cells that intersect with a line. I'm guessing it intuitively just checks what face of a cell intersects with a line, and then navigates to the neighbor on the other side of that face, repeating until the end of the line or grid is reached. I think Wolfenstein did something similar to this to render their grid-based 2.5d worlds.
I can see this being slower than just enumerating through a small list of occupied cells, though it might be faster when there are a lot of them... which shouldn't happen too often (maybe it'd be more a problem with fluid?). (I can see this approach being especially costly when you have to also search neighbors when using a thick ray.)
I wonder what % of occupied cells would be required for the more complex enumeration to be worthwhile. ::thinkingface::
In any case, this is just food for thought. I'm sure this is plenty!


Right on point about everything. The two main showstoppers for Bresenham (actually, DDA in my case) are: #1) Need to check all cells intersected by the ray, and very long rays are common. #2) I need to check not only the cells intersected by the ray but their 27 neighbors too, many of which might be empty. This results in a lot of unnecessary work. For thick rays it's even worse.

(28-05-2021, 10:24 PM)Hatchling Wrote:
Regarding the collision-detection stuff needing to be enabled for raycasts to work (as otherwise the simplex grid isn't built), it might be a good idea to make note of that on the solver in the inspector, just for the sake of making it easier for future users. Perhaps name the collision module "Collision/Queries" and when unfolded, it shows a HelpBox() in there. *shrug*

Will do, thanks for the suggestion Sonrisa
Reply
#12
Hi. Jumping into this thread it seems like the exact kind of thing I'm needing with my project. Has this been added to a particular version of Obi Cloth yet?
Reply
#13
(11-01-2022, 08:34 AM)KyleJohnOConnor Wrote: Hi. Jumping into this thread it seems like the exact kind of thing I'm needing with my project. Has this been added to a particular version of Obi Cloth yet?

Yes, been there since 6.2:
http://obi.virtualmethodstudio.com/manua...eries.html

There's also a "ClothRaycast" sample scene included, with sample code.
Reply
#14
Ah I actually just found that manual page as well! Gran sonrisa Perfect.

One question is: Will the query return anything if the Obi solver has been disabled? 
For some context: I'm moving a cloth around and nailing it in place. Once the player is happy with the placement: the Obi solver for this particular cloth gets disabled to 'freeze' the cloth in place. Would a spatial query raycast return true even though the obi solver in the path of the raycast is disabled?
Reply
#15
(11-01-2022, 08:53 AM)KyleJohnOConnor Wrote: Ah I actually just found that manual page as well! Gran sonrisa Perfect.

One question is: Will the query return anything if the Obi solver has been disabled? 
For some context: I'm moving a cloth around and nailing it in place. Once the player is happy with the placement: the Obi solver for this particular cloth gets disabled to 'freeze' the cloth in place. Would a spatial query raycast return true even though the obi solver in the path of the raycast is disabled?

Yes, queries will be performed against the most up-to-date data provided by the solver. A disabled solver simply does not update this data, but it's still there.

If you want to ignore queries against a disabled solver, check whether the solver is disabled before performing the query.
Reply
#16
Also, note there's a known bug in spatial queries when using the Burst backend. Has been fixed in development, but not released yet. For an explanation and fix, see this thread:

http://obi.virtualmethodstudio.com/forum...-3219.html
Reply