0

I'm having a bit of issue trying to get meshes I import into my program to have cloth simulation physics using a particle/spring system. I'm kind of a beginner into graphics programming, so sorry if this is super obvious and I'm just missing something. I'm using C++ with OpenGL, as well as Assimp to import the models. I'm fairly sure my code to calculate the constraints/springs and step each particle is correct, as I tested it out with generated meshes (with quads instead of triangles), and it looked fine, but idk.

I've been using this link to study up on how to actually do this: https://nccastaff.bournemouth.ac.uk/jmacey/MastersProjects/MSc2010/07LuisPereira/Thesis/LuisPereira_Thesis.pdf

What it looks like in-engine: https://www.youtube.com/watch?v=RyAan27wryU

I'm pretty sure it's an issue with the connections/springs, as the imported model thats just a flat plane seems to work fine, for the most part. The other model though.. seems to just fall apart. I keep looking at papers on this, and from what I understand everything should be working right, as I connect the edge/bend springs seemingly correctly, and the physics side seems to work from the flat planes. I really can't figure it out for the life of me! Any tips/help would be GREATLY appreciated! :)


Code for processing Mesh into Cloth:

// Container to temporarily hold faces while we process springs
std::vector<Face> faces;

// Go through indices and take the ones making a triangle.
// Indices come from assimp, so i think this is the right thing to do to get each face?
for (int i = 0; i < this->indices.size(); i+=3)
{
        std::vector<unsigned int> faceIds = { this->indices.at(i), this->indices.at(i + 1), this->indices.at(i + 2) };
        Face face;
        face.vertexIDs = faceIds;
        faces.push_back(face);
}

// Iterate through faces and add constraints when needed.
for (int l = 0; l < faces.size(); l++)
{

    // Adding edge springs.
    Face temp = faces[l];
    makeConstraint(particles.at(temp.vertexIDs[0]), particles.at(temp.vertexIDs[1]));
    makeConstraint(particles.at(temp.vertexIDs[0]), particles.at(temp.vertexIDs[2]));
    makeConstraint(particles.at(temp.vertexIDs[1]), particles.at(temp.vertexIDs[2]));


    // We need to get the bending springs as well, and i've just written a function to do that.
    for (int x = 0; x < faces.size(); x++)
    {
        Face temp2 = faces[x];
        if (l != x)
        {
            verticesShared(temp, temp2);
        }

    }
}

And heres the code where I process the bending springs as well:

// Container for any indices the two faces have in common. 
std::vector<glm::vec2> traversed;

// Loop through both face's indices, to see if they match eachother. 
for (int i = 0; i < a.vertexIDs.size(); i++)
{
    for (int k = 0; k < b.vertexIDs.size(); k++)
    {

        // If we do get a match, we push a vector into the container containing the two indices of the faces so we know which ones are equal.
        if (a.vertexIDs.at(i) == b.vertexIDs.at(k))
        {
            traversed.push_back(glm::vec2(i, k));
        }
    }
    // If we're here, if means we have an edge in common, aka that we have two vertices shared between the two faces.
    if (traversed.size() == 2)
    {
        // Get the adjacent vertices.
         int face_a_adj_ind = 3 - ((traversed[0].x) + (traversed[1].x));
         int face_b_adj_ind = 3 - ((traversed[0].y) + (traversed[1].y));

        // Turn the stored ones from earlier and just get the ACTUAL indices from the face. Indices of indices, eh. 
        unsigned int adj_1 = a.vertexIDs[face_a_adj_ind];
        unsigned int adj_2 = b.vertexIDs[face_b_adj_ind];
        // And finally, make a bending spring between the two adjacent particles. 
        makeConstraint(particles.at(adj_1), particles.at(adj_2));
    }
}
Jordie
  • 1
  • 1
  • Try connecting your mesh to an animated skeletal ( connected bones like in milkshape ). You can animate the bone on milkshape itself and apply to your mesh. – seccpur Feb 25 '18 at 06:37
  • I COULD do that but I'd much rather learn how to do it this way!! Just because I think it'd be interested to know ^^ – Jordie Feb 25 '18 at 07:01
  • Can you try to collect the relevant code pieces and show them? I know that this is probably very hard for such a system but the code you show in this question doesn't really tell a lot. Also, please try to keep your question self-contained (i.e. explain the relevant concepts). Nobody is going to read an entire thesis to answer your question. – Nico Schertler Feb 26 '18 at 14:40

0 Answers0