New btInternalEdgeUtility has been added

sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: New btInternalEdgeUtility has been added

Post by sparkprime »

I tried today's svn and I can no-longer reproduce the small difference I made the video about. This is good because I don't have time to write a test case :)

All the meshes still seem to be double-sided though? I came to actually quite like the idea of single sided triangles because if you have a wall made of two big parallel triangles facing in opposite directions with a few inches gap between them, it stops projectiles getting jammed inside the wall. However this is still happening with latest svn (unless I built it wrong or something).
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: New btInternalEdgeUtility has been added

Post by Erwin Coumans »

sparkprime wrote:I tried today's svn and I can no-longer reproduce the small difference I made the video about. This is good because I don't have time to write a test case :)

All the meshes still seem to be double-sided though?
Great, thanks for testing it.
two big parallel triangles facing in opposite directions with a few inches gap between them
This is considered bad artwork :-)

The btInternalEdgeUtility only acts on contacts on an edge boundary, so it won't help in general. So in our current implementation it is not the mesh but the btInternalEdgeUtility that assumes single-sided triangles by default. This means that it adjusts the normal (for contacts on edges) in the direction of the triangle normal, even if the object is mainly on the other side of the triangle. You could modify the code to deal with single-sided triangle meshes in general, but that is a separate topic.

The options BT_TRIANGLE_CONCAVE_DOUBLE_SIDED+BT_TRIANGLE_CONVEX_DOUBLE_SIDED will make an attempt to adjust the contact normal independent of triangle normal.
Thanks,
Erwin
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: New btInternalEdgeUtility has been added

Post by sparkprime »

Erwin Coumans wrote:
two big parallel triangles facing in opposite directions with a few inches gap between them
This is considered bad artwork :-)
Is there a better way to do it with triangles though? With hulls / boxes it would work flawlessly but tool support for those is less common. What artists like to do is just do a low poly mesh first as a placeholder as they're building up the scene. Then they do a highpoly mesh for graphics and reuse the placeholder mesh for distant renders and for physics. So it's nice if this can be the typical workflow, with only a minority of problems to be 'corrected' after testing by adding convex shapes in key places.
The btInternalEdgeUtility only acts on contacts on an edge boundary, so it won't help in general. So in our current implementation it is not the mesh but the btInternalEdgeUtility that assumes single-sided triangles by default. This means that it adjusts the normal (for contacts on edges) in the direction of the triangle normal, even if the object is mainly on the other side of the triangle. You could modify the code to deal with single-sided triangle meshes in general, but that is a separate topic.
Erwin
Ah that is interesting... I have a contact_added hack for gimpact meshes that makes them 1-way by reflecting the contact normal if it is not pointing within 90 degrees of the inferred triangle normal. I might try that but should it be used before or after the edge normal adjustment? Seems like it might break things.
edl
Posts: 16
Joined: Tue Jul 08, 2008 7:28 am

Re: New btInternalEdgeUtility has been added

Post by edl »

:? i encount a new problem, when i start my program,don't do anything but leave the car on the ground,(the car didn't crash or contact with any bvhShap, just on a bvhShap),a few minutes later,the car just go crazy,then flew away...its behaviour just like the old version(like i double side problem)..

please test it with my test case....
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: New btInternalEdgeUtility has been added

Post by Erwin Coumans »

edl wrote::? i encount a new problem, when i start my program,don't do anything but leave the car on the ground,(the car didn't crash or contact with any bvhShap, just on a bvhShap),a few minutes later,the car just go crazy,then flew away...its behaviour just like the old version(like i double side problem)..

please test it with my test case....
The car doesn't start in (deep) penetration, and you are not driving/colliding at all? That sounds strange, because without collisions the internal edge utility isn't used.

Can you please file a bug report with more details in the google issue tracker, and attach the test case?
http://code.google.com/p/bullet/issues/list

Thanks a lot,
Erwin
edl
Posts: 16
Joined: Tue Jul 08, 2008 7:28 am

Re: New btInternalEdgeUtility has been added

Post by edl »

Erwin Coumans wrote:
edl wrote::? i encount a new problem, when i start my program,don't do anything but leave the car on the ground,(the car didn't crash or contact with any bvhShap, just on a bvhShap),a few minutes later,the car just go crazy,then flew away...its behaviour just like the old version(like i double side problem)..

please test it with my test case....
The car doesn't start in (deep) penetration, and you are not driving/colliding at all? That sounds strange, because without collisions the internal edge utility isn't used.

Can you please file a bug report with more details in the google issue tracker, and attach the test case?
http://code.google.com/p/bullet/issues/list

Thanks a lot,
Erwin
I am so sorry,it seems my mistake :x
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: New btInternalEdgeUtility has been added

Post by Erwin Coumans »

edl wrote: I am so sorry,it seems my mistake :x
Thanks a lot for the extra testing, I'm glad the btInternalEdgeUtility wasn't the cause for problems.

Thanks,
Erwin
JaZzBrE
Posts: 8
Joined: Tue Jun 02, 2009 5:52 am

Re: New btInternalEdgeUtility has been added

Post by JaZzBrE »

Hi Erwin,
I've been trying to in-place save the btTriangleInfoMap data, but stopped because btHashMap is private and didn't want to hack the bullet code.
Is there any in-place serialization planned for this?

Thanks :)
Ales Mlakar
Zootfly
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: New btInternalEdgeUtility has been added

Post by Erwin Coumans »

JaZzBrE wrote:I've been trying to in-place save the btTriangleInfoMap data, but stopped because btHashMap is private and didn't want to hack the bullet code.
Is there any in-place serialization planned for this?
I want to add btInternalEdgeUtility support for the new btSerializer (and btBulletFile/btBulletWorldImporter)
Although this is not in-place serialization, it is very efficient and more compatible (cross-platform, 32/64bit, big/little endian, float/double precision conversions etc).

Would that be sufficient too?
Thanks,
Erwin
JaZzBrE
Posts: 8
Joined: Tue Jun 02, 2009 5:52 am

Re: New btInternalEdgeUtility has been added

Post by JaZzBrE »

Hi Erwin,
well it seems I've missed this release :) But yes this would probably work! :)
I've managed to save btTriangleInfoMap into our resource file now, with no bullet hacks, I just had to find a way to de-private the class (which is writing a bit hacky public class that looks the same as btHashMap, and just casting it).
On build time I just endian swap the data and save, and on load time I use the initializeFromBuffer on the four arrays.

Thanks a lot!
Ales Mlakar
Zootfly
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: New btInternalEdgeUtility has been added

Post by Erwin Coumans »

Ok, btHashMap data is now protected (not private anymore), and some more preparations for btTriangleInfoMap serialization:

http://code.google.com/p/bullet/source/detail?r=2025

Thanks,
Erwin
JaZzBrE
Posts: 8
Joined: Tue Jun 02, 2009 5:52 am

Re: New btInternalEdgeUtility has been added

Post by JaZzBrE »

Hehe good one, thanks! :)

Ales Mlakar
Zootfly
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: New btInternalEdgeUtility has been added

Post by sparkprime »

I updated today and now I get a segfault here

Code: Select all

(gdb) bt
#0  0x08756c9e in btAlignedObjectArray<btTriangleInfo>::capacity() const ()
#1  0x08756bf6 in btHashMap<btHashInt, btTriangleInfo>::findIndex(btHashInt const&) const ()
#2  0x08756872 in btHashMap<btHashInt, btTriangleInfo>::find(btHashInt const&) ()
#3  0x087540c9 in btAdjustInternalEdgeContacts (cp=..., colObj0=0x236a9d50, colObj1=0x2350fbb0, partId0=0, index0=1055, normalAdjustFlags=0)
    at /home/spark/gritengine/dependencies/bullet/src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp:467
temporary workaround is to stop using the edge adjustment utility

any ideas?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: New btInternalEdgeUtility has been added

Post by Erwin Coumans »

sparkprime wrote:I updated today and now I get a segfault here

Code: Select all

(gdb) bt
#0  0x08756c9e in btAlignedObjectArray<btTriangleInfo>::capacity() const ()
#1  0x08756bf6 in btHashMap<btHashInt, btTriangleInfo>::findIndex(btHashInt const&) const ()
#2  0x08756872 in btHashMap<btHashInt, btTriangleInfo>::find(btHashInt const&) ()
#3  0x087540c9 in btAdjustInternalEdgeContacts (cp=..., colObj0=0x236a9d50, colObj1=0x2350fbb0, partId0=0, index0=1055, normalAdjustFlags=0)
    at /home/spark/gritengine/dependencies/bullet/src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp:467
temporary workaround is to stop using the edge adjustment utility

any ideas?

As usual, can you reproduce it in a Bullet demo or share a zipped .bullet file (using Bullet 2.76 this is trivial).

Otherwise, good luck with debugging the code.
Thanks,
Erwin
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: New btInternalEdgeUtility has been added

Post by sparkprime »

The problem is that I'm using compounds containing bvh mesh data as well as other primitives. I am using this hack locally to fix this problem. I suggest you at least put in the assert and that you consider redesigning things at some point in the future to make Bullet less fragile for this kind of use case. I really think a 'bvh of primitives' is the way forward, it's much simpler, more powerful, and more robust than the current collision shape system.

Code: Select all

Index: src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp
===================================================================
--- src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp     (revision 2044)
+++ src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp     (working copy)
@@ -2,6 +2,7 @@
 
 #include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h"
 #include "BulletCollision/CollisionShapes/btTriangleShape.h"
+#include "BulletCollision/CollisionShapes/btCompoundShape.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 #include "BulletCollision/NarrowPhaseCollision/btManifoldPoint.h"
 #include "LinearMath/btIDebugDraw.h"
@@ -456,7 +457,24 @@
        if (colObj0->getCollisionShape()->getShapeType() != TRIANGLE_SHAPE_PROXYTYPE)
                return;
 
-       btBvhTriangleMeshShape* trimesh = (btBvhTriangleMeshShape*)colObj0->getRootCollisionShape();
+       const btCollisionShape *root = colObj0->getRootCollisionShape();
+       if (root->getShapeType() == COMPOUND_SHAPE_PROXYTYPE) {
+               const btCompoundShape *compound = (const btCompoundShape*) root;
+               // hunt for a trimesh in the compound
+               int found = 0;
+               for (int i=0 ; i<compound->getNumChildShapes() ; ++i) {
+                       const btCollisionShape *s = compound->getChildShape(i);
+                       if (s->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE) {
+                               found++;
+                               root = s;
+                       }
+               }
+               assert(found==1);
+       }
+
+    assert(root->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE);
+
+       btBvhTriangleMeshShape* trimesh = (btBvhTriangleMeshShape*)root;
        btTriangleInfoMap* triangleInfoMapPtr = (btTriangleInfoMap*) trimesh->getTriangleInfoMap();
        if (!triangleInfoMapPtr)
                return;