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{
    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.

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{
    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.


1 Answer 1


Assuming that your object is made up of triangle faces, use the center of those triangles for the position data of that particular face.

This will get rid of all duplicate vertex data.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .