开发者

Loading a Bullet Physics mesh from a file

I'm trying to set up a city environment with Ogre and B开发者_StackOverflow社区ullet, but I'm having trouble figuring out how to load meshes into Bullet. Google shows references to a Collada importer, but that seems to have been removed from the SVN.

The Ogre mesh would be the best thing to import, but I have the .dae and .blend files as well and could use those if possible.


I had the same requirement when using Bullet with Irrlicht. I found no solution apart from writing the physics loading code myself. I used an object naming convention in the 3d editor, and when loading a model, I iterated through the sub-objects and constructed a suitable btRigidBody for each tagged object.

E.g.

        if (needsBody) {
            if (prefix == "ball") {
                body = createSphereBody(mesh, density);
            }
            else if (...

Similarly with joints:

            if (parent && parent->body) {
                // add constraint
                ...
                if (prefix == "ball") {
                    // ball/socket joint                    
                    constraint = new btGeneric6DofConstraint(
                            *parent->body, *body, frameInA, frameInB, true);
                }
                else if (...

The createSphereBody() function calculated the radius from the mesh verts.

Hope that helps.


If you're using 3DS Max for modeling, you can use the OgreMax plugin for exporting the scene fro OGRE, and the bullet plugin for 3DS Max to export physics objects. You can load those two sets separately as OGRE nodes and bullet objects, and combine the physics/graphics models based on their names.

This is how I did it in my own game:

Source: https://github.com/SabinT/Wings-Of-Chaos

Demo: http://www.youtube.com/watch?v=eryWgIuqC7I

I stopped working on this a long time ago, but hope this code proves helpful for someone working on Ogre/Bullet. Perhaps someone will glean some useful code out of this.

You'd be interested in the CsGameLevel.cpp file. The Load() method first loads the Ogre scene, then loads the bullet rigidbodies through the LoadStaticGeometry() method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜