ofMesh vector Xml

Hi,
I am trying to create a mesh by assigning the vertices taken from a vector that I populate through a XML file.

I don’t understand why the vector VertsOriginal is populated but the vertices are not added to the mesh.

ANy hint anyone?

many thanks

here is the code

///////////// xml ///////////

//This is how you would load that very same file
ofxXmlSettings settings;
if(settings.loadFile("../../../SYNESTHESYA_DRAWPOLYGONS_v02/bin/data/positions.xml")){
    
    /////setting the color from XML
    settings.pushTag("color");
    r= settings.getValue("R",1);
    g= settings.getValue("G",1);
    b= settings.getValue("B",1);
    settings.popTag();
    

    ///setting the Points
    settings.pushTag("positions");
    int numberOfSavedPoints = settings.getNumTags("position");
    for(int i = 0; i < numberOfSavedPoints; i++){
        settings.pushTag("position", i);
        
        ofPoint polygonVertex;
        polygonVertex.x = settings.getValue("X", 0);
        polygonVertex.y = settings.getValue("Y", 0);
        polygonVertex.z = settings.getValue("Z", 0);

// meshOriginal.addVertex(polygonVertex); // make a new vertex

        vertsOriginal.push_back(polygonVertex);
        vertsWarped.push_back(polygonVertex);

        printf("vertsOriginal %lu \n", vertsOriginal.size());

        settings.popTag();
    }
    
    settings.popTag(); //pop position
}
else{
    ofLogError("Positions file did not load!");
}

/////////////end xml ////////////////

////////MESH



for (int y = 0; y < ofGetHeight(); y++){
    for (int x = 0; x<ofGetWidth(); x++){
        meshOriginal.addVertex(polygonVertex); // make a new vertex
        meshOriginal.addColor(ofFloatColor(0,0,0));  // add a color at that vertex
    }
}

// now it's important to make sure that each vertex is correctly connected with the
// other vertices around it. This is done using indices, which you can set up like so:
for (int y = 0; y<ofGetHeight()-1; y++){
    for (int x=0; x<ofGetWidth()-1; x++){
        meshOriginal.addIndex(x+y*ofGetWidth());               // 0
        meshOriginal.addIndex((x+1)+y*ofGetWidth());           // 1
        meshOriginal.addIndex(x+(y+1)*ofGetWidth());           // 10
        
        meshOriginal.addIndex((x+1)+y*ofGetWidth());           // 1
        meshOriginal.addIndex((x+1)+(y+1)*ofGetWidth());       // 11
        meshOriginal.addIndex(x+(y+1)*ofGetWidth());           // 10
    }
}
meshOriginal = meshWarped;

printf("nume vertices %d \n", meshOriginal.getNumVertices());


/////////MESH

Why are you adding verts and indices to a mesh based on the height and width of the screen ? Is that really what you want to do ?

Then it looks like you throw away what was in meshOriginal by copying meshWarped (which i dont see any other usage of ) into it at the end of your posted code:

If both of the above are correct and intended then please try to post some self contained snippet using perhaps hardcoded values for the verts and indices (ie remove all the xml parsing stuff since its irrelevant hopefully) and I can try to help you .

Thanks

Hi,
I am basically using the example from the documentation.
I just changed height and width assuming that that was the window size.

The meshWarped is a vector that is used to warp the points with the audio.
i used the ofxFFT addon.
Basically just tried to modify the advanced example.

here is the cleaned up code

#include “ofApp.h”

//--------------------------------------------------------------
void ofApp::setup() {

ofBackground(255);
ofSetFrameRate(30);

fftLive.setMirrorData(false);
fftLive.setup();

string guiPath = "audio.xml";
gui.setup("audio", guiPath, 20, 20);
gui.add(audioThreshold.setup("audioThreshold", 1.0, 0.0, 1.0));
gui.add(audioPeakDecay.setup("audioPeakDecay", 0.915, 0.0, 1.0));
gui.add(audioMaxDecay.setup("audioMaxDecay", 0.995, 0.0, 1.0));

gui.add(audioMirror.setup("audioMirror", true));
gui.loadFromFile(guiPath);

//////my shape/////

///////////// xml ///////////

//This is how you would load that very same file
ofxXmlSettings settings;
if(settings.loadFile("../../../SYNESTHESYA_DRAWPOLYGONS_v02/bin/data/positions.xml")){
    
    /////setting the color from XML
    settings.pushTag("color");
    r= settings.getValue("R",1);
    g= settings.getValue("G",1);
    b= settings.getValue("B",1);
    settings.popTag();
    

    ///setting the Points
    settings.pushTag("positions");
    int numberOfSavedPoints = settings.getNumTags("position");
    for(int i = 0; i < numberOfSavedPoints; i++){
        settings.pushTag("position", i);

// ofPoint polygonVertex; /// this is declared in ofApp.h
polygonVertex.x = settings.getValue(“X”, 0);
polygonVertex.y = settings.getValue(“Y”, 0);
polygonVertex.z = settings.getValue(“Z”, 0);

// this is an option that I tried: after getting I get the polygon value I try to add a vertex with the value of vertsOriginal[i]. It didn’t work.

// meshOriginal.addVertex(vertsOriginal[i]);

        vertsOriginal.push_back(polygonVertex);
        vertsWarped.push_back(polygonVertex);
        
        printf("vertsOriginal X %f \n", vertsOriginal[i].x);
        printf("vertsOriginal Y %f \n", vertsOriginal[i].y);
        printf("vertsOriginal Z %f \n", vertsOriginal[i].z);
        printf("vertsOriginal %lu \n", vertsOriginal.size());

        settings.popTag();

    }
    
    settings.popTag(); //pop position

}
else{
    ofLogError("Positions file did not load!");
}

/////////////end xml ////////////////

////////MESH

// this is another option that I tried: I try to add all the verteces with the value of vertsOriginal, to the meshOriginal. It didn’t work.

// meshOriginal.addVertices(vertsOriginal);

//this is the example taken from OF documentation.
// I just susbtituted height and width with the window h and w.
for (int y = 0; y < ofGetHeight(); y++){
for (int x = 0; x<ofGetWidth(); x++){
meshOriginal.addVertex(polygonVertex); // make a new vertex
meshOriginal.addColor(ofFloatColor(0,0,0)); // add a color at that vertex
}
}

// now it's important to make sure that each vertex is correctly connected with the
// other vertices around it. This is done using indices, which you can set up like so:
for (int y = 0; y<ofGetHeight()-1; y++){
    for (int x=0; x<ofGetWidth()-1; x++){
        meshOriginal.addIndex(x+y*ofGetWidth());               // 0
        meshOriginal.addIndex((x+1)+y*ofGetWidth());           // 1
        meshOriginal.addIndex(x+(y+1)*ofGetWidth());           // 10
        
        meshOriginal.addIndex((x+1)+y*ofGetWidth());           // 1
        meshOriginal.addIndex((x+1)+(y+1)*ofGetWidth());       // 11
        meshOriginal.addIndex(x+(y+1)*ofGetWidth());           // 10
    }
}

//I have to set meshOriginal = meshWarped so that the initial state of the mesh is the same.

meshOriginal.addVertices(vertsOriginal);
meshWarped=meshOriginal;
printf("nume vertices %d \n", meshOriginal.getNumVertices());


/////////MESH

}

//--------------------------------------------------------------
void ofApp::update() {

fftLive.setThreshold(audioThreshold);
fftLive.setPeakDecay(audioPeakDecay);
fftLive.setMaxDecay(audioMaxDecay);
fftLive.setMirrorData(audioMirror);
fftLive.update();

//---------------------------------------------------------- dispacing mesh using audio.

int numOfVerts = meshOriginal.getNumVertices();
float * audioData = new float[numOfVerts];
fftLive.getFftPeakData(audioData, numOfVerts);
float meshDisplacement = 100;

for(int i=0; i<numOfVerts; i++) {
    float audioValue = audioData[i];
    ofVec3f & vertOriginal = vertsOriginal[i];
    ofVec3f & vertWarped = vertsWarped[i];
    
    ofVec3f direction = vertOriginal.getNormalized();
    vertWarped = vertOriginal + direction * meshDisplacement * audioValue;
}

delete[] audioData;

}

//--------------------------------------------------------------
void ofApp::draw() {
ofSetColor(r,g,b);

cam.begin();
meshWarped.draw();
cam.end();

gui.draw();

}

Hopefully you might help.

thanks!