crueleva1 / dynamica

Automatically exported from code.google.com/p/dynamica
0 stars 0 forks source link

Game Friendly Optimizations #18

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I have 3 small feature requests for Dynamica\btBulletWorldImporter to make this 
pipeline optimal for usage in games. These optimizations would probably improve 
performance in Maya as well.

1. Static collision geometry (currently created as Passive RigidBodies with a 
mass of 0) don't actually require btRigidBody classes at run time. Having 
btRigidBodys for such geo unnecessarily adds run time memory usage and sucks 
down cpu cycles. If we could have either a flag specified at load time via 
btBulletWorldImporter to have all Passive Objects created as just 
btCoillisionObjects or have an option in Dynamica to specify which Passive 
Objects are created with btRigidBodies. If its decided to remove the 
btRigidBodies in Maya for such geo, just note that currently the 
‘restitution’ and ‘friction’ values are set in the RigidBody Maya node 
class\panel yet those values are stored in Bullet in the btCollisionObject 
class (and would still be needed to be settable in Maya).

2. Currently all Passive Meshes are being created as 
btGimpactTriangleMeshShapes. For games we need the most optimal collision shape 
for concave static collision geo, which in Bullet would be be btOptimizedBvhs. 
To use Dynamica as a one step exporter for games we really need to be able to 
create these things before serialization to disk.

3. Relatively minor issue, but individual Meshes in Dynamica are being created 
as a single btGimpactTriangleMeshShapes inside of a btCompoundShape, which is 
an unnecessary layer of indirection and expense.

Thank you!

Original issue reported on code.google.com by cont...@vicariousentertainment.com on 15 Feb 2011 at 2:35

GoogleCodeExporter commented 8 years ago

The latest trunk has the option to create btBvhTriangleMeshShape (named 
BvhMesh), and it won't embed this in a btCompoundShape. This should deal with 
(2) and (3).

I didn't fix (1) yet.

Original comment by erwin.coumans on 12 Mar 2011 at 6:03

GoogleCodeExporter commented 8 years ago
Issue 15 has been merged into this issue.

Original comment by erwin.coumans on 12 Mar 2011 at 6:19

GoogleCodeExporter commented 8 years ago
Good to hear!

Would it be possible to have the btBvhTriangleMeshShapes converted to 
btOptimizedBvhs during the export process? Would there ever be a scenario where 
we wouldn't want them to be Optimized once saved to disk? Its simple enough to 
convert them to optimized inside the WorldImporter on load but then a build 
step is required to move the optimization stage out of a run time game load.

Original comment by cont...@vicariousentertainment.com on 15 Mar 2011 at 12:04

GoogleCodeExporter commented 8 years ago
So I was playing around with this stuff in the new 2.78 release a little in 
hopes that OptimizedBVHs would solve some of my collision problems in my game 
and I've learned a few things.

First off ignore my previous comment, the change you did does create 
OptimizedBVHs. However the new BVH Shape Type feature in Dynamica didn't quite 
make it into 2.78. In collisionShapeNode.cpp of the Dynamica project, the index 
for the BVH option was incorrect...

 fnEnumAttr.addField("Plane", 6);
    fnEnumAttr.addField("BvhMesh", 6); <-- Line 71 in collisionShapeNode::initialize()
    fnEnumAttr.setKeyable(true);

After much pain I managed to get the Dynamica project to compile (never used 
cmake before and the 2008 .net project file it generated was missing some libs 
and such), and changed that 6 to a 7 and now type BVHs are accessable in Maya 
and work! This has actually been fixed in the latest trunk as someone has added 
another new Shape Type after it and noticed the error. However, once you've 
created Optimized BVHs in a scene in Maya, Maya will crash when you close the 
file down (doesn't corrupt the file at least). 

Next I had to modfiy btWorldImporter to get the saved OptimizedBVHs to be used. 
I simply had to undef some defined out code in 
btBulletWorldImporter::convertCollisionShape, line 565..

    btOptimizedBvh* bvh = 0;
#if 0
    if (trimesh->m_quantizedFloatBvh)
    {
             btOptimizedBvh** bvhPtr = m_bvhMap.find(trimesh->m_quantizedFloatBvh);
        if (bvhPtr && *bvhPtr)
        {
            bvh = *bvhPtr;
        } else
        {
            bvh = createOptimizedBvh();
            bvh->deSerializeFloat(*trimesh->m_quantizedFloatBvh);
        }
    }
... etc.

Changing the define got that working fine and I've noticed no problems with 
this code in effect. Deallocation and all is good, not sure why it was defined 
out in the first place.

So to get back to the original Issues, #2 is fixed if you change the Shape type 
manually, and no CompoundShape is generated in that case. However I would say 
#3 is still an issue as every other Shape Type is still in a btCompoundShape 
even when there is only one shape. 

Having #1 implimented somehow would be great too. btWorldImporter isn't setup 
to handle pure btCollisionObjects without accompaning btRigidBodies as is but 
its a fairly simple conversion. I've done it myself locally and I could submit 
a patch for that if you like.

Thanks alot for the OptimizedBVHs feature though, nice to have them in game now!

Original comment by cont...@vicariousentertainment.com on 13 Sep 2011 at 3:42

GoogleCodeExporter commented 8 years ago
As requested I've attached the SVN patch file for the modification to 
btWorldImporter to allow it to load, store and access btCollisionObjects 
without having Rigid Bodies attached. If issue 1 above does get implimented 
these changes would be necesary. Though you may disagree with one direction I 
took. It appears the WorldImporter was originaly written with the intention of 
all types of bodies (rigid, soft & plain CollisionObjects) be stored in a 
single list but the access functions are named just for RigidBodies. I 
seperated the btCollisionObjects into their own lists and gave them their own 
access functions and changed the type of the RB lists to btRigidBody as I felt 
it would be simpler, clearer and closer to the original intent? But its 
certainly possible for them to all be in one list still if desired.

Original comment by cont...@vicariousentertainment.com on 13 Sep 2011 at 10:27

Attachments:

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
So as it looks like a new version of Bullet is coming out soon, now would be a 
great time to fix up the remaining problems with the OptimizedBVHs coming out 
of Maya.

1. That Defined out code I highlighed two posts above is still defined out and 
you will not get any OptimizedBVHs from .bullet files working at runtime unless 
you enable it.

2. The crash I mentioned is still in 2.80 Dynamica and is a real problem. 
Setting any static mesh in Maya to OpimizedBVH will result in a crash when you 
close that scene in Maya down (load another file, select new file or just try 
to exit). We run out of the box Dynamica 2.80 for Maya 2010 64bit, and I belive 
I originally ran into that issue in a 32bit build. Would you like me to create 
a seperate issue for this crash?

Original comment by cont...@vicariousentertainment.com on 11 Sep 2012 at 4:21

GoogleCodeExporter commented 8 years ago
Well scratch number 2, I added an issue for that previously apparently and its 
now been fixed (issue #24)! Thanks Erwin!

Original comment by cont...@vicariousentertainment.com on 12 Sep 2012 at 12:49

GoogleCodeExporter commented 8 years ago
That code is enabled now:
https://code.google.com/p/bullet/source/browse/trunk/Extras/Serialize/BulletWorl
dImporter/btWorldImporter.cpp#376

Original comment by erwin.coumans on 25 Oct 2012 at 3:38

GoogleCodeExporter commented 8 years ago
Yep! Just got 2.81 intergrated and we're back to running out of the box 
btBulletWorldImporter. #1 in my original post is the only outstanding issue 
left in this thread. The patch I submitted in Comment 5 may be of some use if 
raw btCollisionObjects are ever exported straight out of Dynamica.

Original comment by cont...@vicariousentertainment.com on 30 Oct 2012 at 3:48