Building a mesh with FFT data (3d spectrogram)

I’m working on making a little toy that would build a 3D spectrogram from audio input and then saving the mesh out to play with in cinema 4D or maybe 3d print. I’m about 90% there (adding in vertex points for the FFT bins, exporting the mesh). My main issue seems to be properly indexing the mesh points for triangles to properly build across the surface. When the surfaces aren’t made quite right, its a challenge to work with the data in cinema 4d and apply certain transforms to it.

Was trying to pick up some stuff from the MeshfromCamera example, but since that all gets blasted in one iterator it’s a little different than trying to build the surface up procedurally on each frame, but maybe it’s just my for loops being out of range? mesh.setupIndicesAuto tends to make things incorrect as well.

I’m basically taking the FFT data, X is the bin, Y is the intensity in that bin, and then Z axis is time and I’m adding a row of vertices on each frame.

something like this:

  
    for(int i=0; i<eqCols; i++){  
        float x = 1+ofMap(i,0,eqCols, 0, ofGetWidth());  
        float y = 1+ofMap(avgCol[i], 0, maxVol, ofGetHeight(), 0);  
        float z = 1+timePos;  
        mesh.addVertex(ofVec3f(x,y,z));  
    }  

and trying to add in the indexing from the meshfromcamera example just throws some GL errors of nonexistent points.

something like this in a loop:

  
        mesh.addIndex(x+y*width);				// 0  
        mesh.addIndex((x+1)+y*width);			// 1  
        mesh.addIndex(x+(y+1)*width);			// 10  
      
        mesh.addIndex((x+1)+y*width);			// 1  
        mesh.addIndex((x+1)+(y+1)*width);		// 11  
        mesh.addIndex(x+(y+1)*width);			// 10  

I’ve also tried to approach of building the mesh with proper indices first and just using setVertex with the audio data, but that doesn’t seem to work either…the points traverse across my mesh, but one point of the triangles are glued to the first row and the points will reset to 0 after passing through.

Is there a smarter way to be going about this? I can post more code if necessary, but it’s gotten a bit ugly as I’ve tried a few of these implementations.

![](http://forum.openframeworks.cc/uploads/default/2907/Screen shot 2013-05-10 at 6.23.12 PM.png)