# Soft Body rendering from OBJ model

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,
&indi[0],
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;
trans.setIdentity();
trans.setOrigin(btVector3(0,0,0));
LiverSBody->transform(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));
LiverSBody->getCollisionShape()->setMargin(0.1);

float Friction = 0.9;
float Restitution = 0.5;

LiverSBody->setFriction(Friction);
LiverSBody->setRestitution(Restitution);



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, ..).

//btSoftbody.h
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).