Using Bullet Physics Engine on CAL3D Models?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
qez111
Posts: 54
Joined: Mon Apr 28, 2008 9:44 pm

Using Bullet Physics Engine on CAL3D Models?

Post by qez111 »

Is there anyway I could use Bullet Physics Engine (or any other engine) with Cal3D models?
In one of th examples I found in this forum for Bullet Engine in Irrlicht, it uses a function called

Code: Select all

CBulletPhysicsObject::GetTriangleMesh(scene::IMesh* pMesh)
However, the Cal3D node by Klasker is derived from ISceneNode*, and the vertices are drawn only in Render() function of the node, I think, and by using virtual void

Code: Select all

drawIndexedTriangleList(const S3DVertex* vertices,
			u32 vertexCount, const u16* indexList, u32 triangleCount) = 0;
in the render() function. So, how do I get the mesh to be passed to GetTriangleMesh, in order to use the cal3d model for physics collisions in Bullet Engine? Is there a method by which I can get a mesh from the ISceneNode* or something? Or do I need to adopt a completely different approach?

Thanks.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Does the Cal3D Node not have a getMesh function? Or any way of getting the mesh? How is the Cal3D Node created? Is a mesh not created first and then the node made from the mesh?

If not then you may need to edit to to be able to get an IMesh from it, or you just need the vertices and indices probably and then those can be passed to Bullet to tell it the structure of the mesh, that's probably how the GetTriangleMesh function works, just takes the vertices and indices out of the IMesh and passes them to Bullet.
Image Image Image
qez111
Posts: 54
Joined: Mon Apr 28, 2008 9:44 pm

Post by qez111 »

In the Klasker's Wrapper, there are two main classes: CCal3DNode (based from ISceneNode) and CCal3DModel.
CCal3DNode is created using the class CCal3DModel. CCal3DModel loads and stores the meshes in the native Cal3D format, for example, the following is the chunk that loads the mesh, into native Cal3D classes.

Code: Select all

for ( s32 meshId = 0; meshId < meshCount; meshId++ )
    {
        CalCoreMesh* mesh = Model->getCoreMesh( meshId );
        s32 subCount = mesh->getCoreSubmeshCount();
        
        //--------------------------------------------------------//
        for ( s32 subId = 0; subId < subCount; subId++ )
        {
            CalCoreSubmesh* submesh = mesh->getCoreSubmesh( subId );
            std::vector< CalCoreSubmesh::Vertex >& vertices = submesh->getVectorVertex();

            //------------------------------------------------------//
            for ( s32 vertId = 0; vertId < vertices.size(); vertId++ )
            {
                CalCoreSubmesh::Vertex& vert = vertices[ vertId ];    // Swap Z and Y coords due to coordinate system
                BoundingBox.addInternalPoint( vert.position.x, vert.position.z, vert.position.y );
            } // for vertId
Therefore its clear that it is not loaded as IMesh* at all.
I guess I will have to write a function that can first create an IMesh*. Assuming this is done, will I also have to update the IMesh* every frame, in render() function of the Node, because CAl3D Models are animated ones...?
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Well you're not going to want an animated physics object as it's just not feasible to do that in real time really. You can use a ragdoll approach to get accurate enough collision detection on animated models or you can just be happy with a bounding box/sphere/capsule.
Image Image Image
qez111
Posts: 54
Joined: Mon Apr 28, 2008 9:44 pm

Post by qez111 »

JP wrote:Well you're not going to want an animated physics object as it's just not feasible to do that in real time really. You can use a ragdoll approach to get accurate enough collision detection on animated models or you can just be happy with a bounding box/sphere/capsule.
I am not necessarily using Cal3D for animating humanoids. In this particular case, i am animating some rigid body object and its vertex count is only around 200 tri. So efficiency is not a problem in this case.

However, my doubt is still not cleared from the previous reply:
.... Assuming this is done, will I also have to update the IMesh* every frame, in render() function of the Node, because CAl3D Models are animated ones...?
I would appreciate if someone can clear the above doubt.
Post Reply