0
\$\begingroup\$

I'm having a hard time struggling with obj files and clothing simulations. I first made the obj file processor class that deals with the typical obj file problem: having multiple indices for vertex position, vertex texture coordinates, and vertex normals like this f 52/49/224 57/54/224 279/270/224. I made a function that shrinks the multiple index arrays to one index array.

class VERTEX{
public:
    glm::vec3 position;
    glm::vec2 uv_coord;
    glm::vec3 normal;
};

std::vector<VERTEX> out_vertices;
std::vector<unsigned int> out_indices;

void reorderData(){
        for(int i=0;i<vertexIndices.size();i++){
            VERTEX vertex;
            // add -1 to each index as indices for obj files start from 1, not 0.
            int vi = vertexIndices[i]-1;
            int uvi = uvIndices[i]-1;
            int ni = normalIndices[i]-1;
            vertex.position = temp_vertices[vi];
            vertex.uv_coord = temp_uvs[uvi];
            vertex.normal = temp_normals[ni];
            //assign new index here for the VERTEX object
            int index = getVertexIndex(vertex);
            //If it's a new index, it means it's a new VERTEX. Store it in out_vertices.
            if(index==out_vertices.size()){
                out_vertices.push_back(vertex);
            }
            out_indices.push_back(index);
        }
    }

Then I use out_vertices and out_indices to set up the VAO, VBO, and EBO for rendering. The problem here is that in the VBO, there are multiple VERTEX objects that have the same position value.

However, in order to do physics simulation, I need a particle class that deals with calculating the force, speed, position for every loop of each cloth particle.

class particle{
public:
    glm::vec3 position;
    glm::vec3 force;
    glm::vec3 speed;
    float mass;
}

And if I just copy the the VERTEX objects' position values to the particle objects, then there will be multiple particle objects with the same position value. But this doesn't seem right as there should be only one particle object for each unique position.

So my solution at the moment is, to first make particle objects that each have unique position values. Then, after each physics loop calculating a particle's speed, force, position, I update all the VERTEX objects whose position value has changed for the corresponding 'position' object. Lastly I update the VBO.

Would this be the right approach? I am afraid that linearly searching the multiple VERTEX objects who have the same position value as the particle object is going to take a lot of time. Any help would be appreciated. Thanks in advance!


To be short what I want to seek advice about is how to seperate and handle the rendering data and the physics simulation data efficiently.

\$\endgroup\$

Your Answer

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

Browse other questions tagged or ask your own question.