rayTest improvements: face normal and broad phase filter

Physics APIs, Physics file formats, Maya, Max, XSI, Cinema 4D, Lightwave, Blender, thinkingParticles™ and other simulation tools, exporters and importers
Post Reply
ben2610
Posts: 4
Joined: Sun Aug 24, 2008 10:22 pm

rayTest improvements: face normal and broad phase filter

Post by ben2610 »

Hi there,

I'm one of the maintainer of the Blender game engine, which uses Bullet as you know. I am working on a set of improvements for the rayCast function for which some minor changes are required in Bullet:

1) possibility to filter out collision objects through callback before testing the ray. This would avoid testing an object that the game engine wants to ignore in any case (X-Ray function). => this is now available in 2.70

2) possibility to return the true face normal on concave mesh shapes. Currently the normal returned by the rayTest function is always oriented towards the ray origin. By returning the true face normal, the application can easily test if it is inside or outside the mesh.

3) possibility to retrieve the hit face on concave mesh shapes. Currently, only the triangle index is returned, which is insufficient in case of compound shape; the collision shape pointer is necessary to identify which child shape got the hit.

I've prepared a patch based on the Bullet version used in Blender (2.67?) but it won't be applicable to Bullet 2.70 because there has been several other changes in this area. I can prepare a patch for 2.70 if there is a consensus to integrate those features for the next release.

The patch can be found here

There is another useful feature for which I don't have a patch yet: the possibility to return more than one hit, by order of proximity. This would require sorting the hits rather than keeping the closest one only. Currently this function can be implemented by running multiple rayTest, each starting from the hit point of the previous rayTest. But it would be faster and more reliable to sort the hit points during the first run of rayTest as the algorithm computes them all in any case.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: rayTest improvements: face normal and broad phase filter

Post by Erwin Coumans »

ben2610 wrote:I'm one of the maintainer of the Blender game engine, which uses Bullet as you know. I am working on a set of improvements for the rayCast function for which some minor changes are required in Bullet:
1) possibility to filter out collision objects through callback before testing the ray. This would avoid testing an object that the game engine wants to ignore in any case (X-Ray function). => this is now available in 2.70
It would be good to upgrade to Bullet 2.70 soon. Shall I do this, or is someone already working on this?
2) possibility to return the true face normal on concave mesh shapes. Currently the normal returned by the rayTest function is always oriented towards the ray origin. By returning the true face normal, the application can easily test if it is inside or outside the mesh.
3) possibility to retrieve the hit face on concave mesh shapes. Currently, only the triangle index is returned, which is insufficient in case of compound shape; the collision shape pointer is necessary to identify which child shape got the hit.
4) There is another useful feature for which I don't have a patch yet: the possibility to return more than one hit, by order of proximity.
All 4 can already be performed using Bullet 2.70 without any patch necessary, it can be implemented in a derived class from RayResultCallback:

(1) -> override RayResultCallback::needsCollision
(2) -> Within the RayResultCallback::addSingleResult callback, the child shape for compound shape is available as rayResult.m_collisionObject->getCollisionShape(). During the rayTest against a btBvhTriangleMeshShape and btCompoundShape, the collision shape has been temporary replaced by the child shape.
(3)-> Same as (2), RayResultCallback::addSingleResult provides the triangle index and collision shape, so you can retrieve the original face normal and store it in your custom version of RayResultCallback.
(4) ->During a single rayTest, you can gather ALL hits and store them in an array. Afterwards sort them to distance.

Is already someone working on upgrading to Bullet 2.70, or shall I help with that?
Erwin
ben2610
Posts: 4
Joined: Sun Aug 24, 2008 10:22 pm

Re: rayTest improvements: face normal and broad phase filter

Post by ben2610 »

(1) -> override RayResultCallback::needsCollision
(2) -> Within the RayResultCallback::addSingleResult callback, the child shape for compound shape is available as rayResult.m_collisionObject->getCollisionShape(). During the rayTest against a btBvhTriangleMeshShape and btCompoundShape, the collision shape has been temporary replaced by the child shape.
(3)-> Same as (2), RayResultCallback::addSingleResult provides the triangle index and collision shape, so you can retrieve the original face normal and store it in your custom version of RayResultCallback.
(4) ->During a single rayTest, you can gather ALL hits and store them in an array. Afterwards sort them to distance.
(1): figured that one out
(2): I didn't quite see that in the code, but I'll look closer
(3): ok
(4): indeed. I was confused with the line if (hitFraction <= m_resultCallback->m_closestHitFraction) in reportHit() that seems to leave out the hit points that are not closer than the previous ones but you just need to keep m_closestHitFraction at 1.0 in your custom RayResultCallback to you get all the hits.
Is already someone working on upgrading to Bullet 2.70, or shall I help with that?
Noone is working on it yet but I was planning to do it myself. Not sure yet when I will have the time to do it.

/ben
ben2610
Posts: 4
Joined: Sun Aug 24, 2008 10:22 pm

Re: rayTest improvements: face normal and broad phase filter

Post by ben2610 »

Within the RayResultCallback::addSingleResult callback, the child shape for compound shape is available as rayResult.m_collisionObject->getCollisionShape(). During the rayTest against a btBvhTriangleMeshShape and btCompoundShape, the collision shape has been temporary replaced by the child shape
I tested rayTest against compound object in Bullet 2.71 and the child shape is not available through the collision object: the replacement that you mention above does not happen. Is it possible to add it, or to add the shape pointer in rayResult?

/ben
ben2610
Posts: 4
Joined: Sun Aug 24, 2008 10:22 pm

Re: rayTest improvements: face normal and broad phase filter

Post by ben2610 »

I've posted a patch for this issue:

http://code.google.com/p/bullet/issues/detail?id=91
hyyou
Posts: 96
Joined: Wed Mar 16, 2016 10:11 am

Re: rayTest improvements: face normal and broad phase filter

Post by hyyou »

I know that this thread is old, but I found it in the first result of google.

The commit from Quick Camel in 2008 (ben2610 ?) does not exist anymore.

Therefore, information in this page is currently very misleading.

For the current solution (2016) , please look at this link instead :-

http://bulletphysics.org/Bullet/phpBB3/ ... hp?t=11154 (May 2016) show a correct way to do this in
http://www.bulletphysics.org/Bullet/php ... ray#p37118 (Mar 2016)
Post Reply