Setting back vertices at theirs initials positions

Hi everyone,

I’m new to OF, and I’d like to thank the whole community for the work.

I created meshes with an image as a source, and i’d like to move the position of vertices when the sound exceed a certain threshold. I succeed making it, but I can’t move vertices back to theirs originals positions.

I used the mesh tutorial available on the website :

In setup :

ofSetFrameRate(60);
        image.loadImage("test.png");
mesh.setMode(OF_PRIMITIVE_POINTS);
float intensityThreshold = 150;
    int w = image.getWidth();
    int h = image.getHeight();
    for (int x=0; x<w; ++x) {
        for (int y=0; y<h; ++y) {
            ofColor c = image.getColor(x, y);
            float intensity = c.getLightness();
            if (intensity >= intensityThreshold) {
                float saturation = c.getSaturation();
                float z = ofMap(saturation, 0, 255, -100, 100);
                ofVec3f pos(x, y, 0.0);
                mesh.addVertex(pos);
                ofColor meshColor = (255, 255, 255) ;
                mesh.addColor(meshColor);
                offsets.push_back(ofVec3f(ofRandom(0,100000), ofRandom(0,100000), ofRandom(0,100000)));
            }
        }
    }

(And the sound setup)

In Update :

int numVerts = mesh.getNumVertices();
    for (int i=0; i<numVerts; ++i) {
        ofVec3f vert = mesh.getVertex(i);
        float time = ofGetElapsedTimef();
        float timeScale = 5.0;
        float displacementScale = 0.75;
        ofVec3f timeOffsets = offsets[i];

if (scaledVol > 0.5) {
                    
                    
                    vert.x += (ofSignedNoise(time*timeScale+timeOffsets.x)) * displacementScale * scaledVol * 190.0f;
                    vert.y += (ofSignedNoise(time*timeScale+timeOffsets.y)) * displacementScale * scaledVol * 190.0f;
                    vert.z += (ofSignedNoise(time*timeScale+timeOffsets.z)) * displacementScale * scaledVol * 190.0f;
                    mesh.setVertex(i, vert);
                    }

So now, when the threshold exceed 0.5, my vertices propagate but doesn’t come back at theirs originals positions.

I tried to store the index, tried mesh.getVertex with mesh.setVertex but it failed.

Any Ideas ?

Thanks !

(Edit : Sorry if my english may be bad, I’m French)