As part of my master thesis I have to do an softbody simulation.

I 'm using Bullet Physics engine.

I'm trying to render softbody, create from Meshes, with Shaders in OpenGL but the object doesnt seem to be rendered (it doesnt appear in the window).

I'm not sure if the problem is because of the way I created the sobtbody or the way I render it. Thank you in advance.

I'm using this function for creating a softBody from my OBJ Liver model :

        btScalar* verti = new btScalar[3 * (Liver.getMeshes()[0].vertices.size())];
        for (int i = 0; i < Liver.getMeshes()[0].vertices.size(); i++)
            verti[3 * i] = Liver.getMeshes()[0].vertices[i].Position.x;
            verti[3 * i + 1] = Liver.getMeshes()[0].vertices[i].Position.y;
            verti[3 * i + 2] = Liver.getMeshes()[0].vertices[i].Position.z;

        int* indi = new int[Liver.getMeshes()[0].indices.size()];
        for (int i = 0; i < Liver.getMeshes()[0].indices.size(); i++)
            indi[i] = Liver.getMeshes()[0].indices[i];

        btSoftBody* LiverSBody = btSoftBodyHelpers::CreateFromTriMesh(softBodyWorldInfo, verti,
            int(Liver.getMeshes()[0].indices.size()) / 3);

        LiverSBody->m_cfg.kVC = 0.5;
        btSoftBody::Material* pSpMat = LiverSBody->appendMaterial();
        //LiverSBody->m_materials[0]->m_kLST = 0.5;
        pSpMat->m_kLST = 1.0;
        LiverSBody->setPose(false, true);

        btTransform trans;

        LiverSBody->generateBendingConstraints(2, pSpMat);
        LiverSBody->m_cfg.piterations = 2;
        LiverSBody->m_cfg.kDF = 1.0;
        LiverSBody->m_cfg.kSRHR_CL = 1;
        LiverSBody->m_cfg.kSR_SPLT_CL = 0;

        LiverSBody->setTotalMass(10, true);
        LiverSBody->scale(btVector3(0.02, 0.02, 0.02));

        float Friction = 0.9;
        float Restitution = 0.5;



I'm using this class for loading and visualizing model https://learnopengl.com/code_viewer_gh.php?code=includes/learnopengl/model.h I need to extract from the softBody some data (Position, normal, texCoords, tangent and bitangent) to fill the vertex buffer objects but i don't know where to find most of it... I know that the position and the normals are in the softbody nodes but i can't find the other information needed (texCoords, ..).

struct Node : Feature
        btVector3 m_x;       // Position
        btVector3 m_q;       // Previous step position
        btVector3 m_v;       // Velocity
        btVector3 m_f;       // Force accumulator
        btVector3 m_n;       // Normal
        btScalar m_im;       // 1/mass
        btScalar m_area;     // Area
        btDbvtNode* m_leaf;  // Leaf data
        int m_battach : 1;   // Attached

You can't mix immediate mode (glBegin, glEnd, etc.) with the programmable pipeline (shaders) like this. You either need to stick to immediate mode (you really shouldn't, it's 2019) and use shaders that are compatible with it (using the built-in variables instead of attributes) or use a modern OpenGL version and pass the model information as vertex buffer objects (this would be the more preferred option in my opinion).

  • \$\begingroup\$ More info on the former approach in this forum thread \$\endgroup\$ – Bálint Aug 6 '19 at 8:32
  • \$\begingroup\$ thank you, I took the skeleton of this function from a forum but the answer was a bit dated so I wasn't sure if the version of OpenGL was compatible with mine. Thank you for clearing that up ! \$\endgroup\$ – franadam Aug 6 '19 at 9:07
  • \$\begingroup\$ I'm actually using vertex buffer for my OBJ model but i don't know how to extract that information from a bullet Softbody. \$\endgroup\$ – franadam Aug 6 '19 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.