Help How to query Obi geometry with raycasts? - Printable Version +- Obi Official Forum (https://obi.virtualmethodstudio.com/forum) +-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html) +--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html) +--- Thread: Help How to query Obi geometry with raycasts? (/thread-2936.html) Pages:
1
2
|
RE: How to query Obi geometry with raycasts? - josemendez - 29-05-2021 (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. 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: Will do, thanks for the suggestion RE: How to query Obi geometry with raycasts? - KyleJohnOConnor - 11-01-2022 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? RE: How to query Obi geometry with raycasts? - josemendez - 11-01-2022 (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/manual/6.3/scriptingqueries.html There's also a "ClothRaycast" sample scene included, with sample code. RE: How to query Obi geometry with raycasts? - KyleJohnOConnor - 11-01-2022 Ah I actually just found that manual page as well! 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? RE: How to query Obi geometry with raycasts? - josemendez - 11-01-2022 (11-01-2022, 08:53 AM)KyleJohnOConnor Wrote: Ah I actually just found that manual page as well! Perfect. 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. RE: How to query Obi geometry with raycasts? - josemendez - 11-01-2022 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/thread-3219.html |