int CloudsVisualSystemLaplacianTunnel::loadMesh(ofVbo &vbo, string path) { char* buffer; long size; //cout << "path is " << path << endl; ifstream data( ofToDataPath(path, true).c_str(), ios::in | ios::binary); data.seekg(0, ios::end); size = data.tellg(); data.seekg(0, ios::beg); buffer = new char[size]; data.read(buffer, size); data.close(); unsigned int *ints = (unsigned int *) buffer; int numPts = ints[0]; int numTriangles = ints[1]; float *pts = (float *) (ints+2); for(int i = 0; i < numPts; i++){ ofVec3f p(pts[i*3+0],pts[i*3+1],pts[i*3+2]); center += p; min = ofVec3f(MIN(min.x,p.x), MIN(min.y,p.y), MIN(min.z,p.z)); max = ofVec3f(MAX(max.x,p.x), MAX(max.y,p.y), MAX(max.z,p.z)); } center /= numPts; unsigned int * indices = ints + 2 + numPts*6; //not sure what is enable or disable by default vbo.enableIndices(); vbo.enableNormals(); vbo.disableColors(); vbo.disableTexCoords(); vbo.setVertexData(pts,3,numPts,GL_STATIC_DRAW,sizeof(float)*3); vbo.setNormalData(pts+numPts*3,numPts,GL_STATIC_DRAW,sizeof(float)*3); vbo.setIndexData(indices,numTriangles*3,GL_STATIC_DRAW); //cout << "File " << path << " has " << numTriangles << " triangles " << endl; return numTriangles*3; }
/** * Add a quad to the mesh with clockwise front face vertex order */ void addQuad(ofVec3f const & bottomLeft, ofVec3f const & topLeft, ofVec3f const & topRight, ofVec3f const & bottomRight) { mesh.enableNormals(); vbo.enableNormals(); ofVec3f v1 = topLeft; ofVec3f v2 = topRight; ofVec3f v3 = bottomRight; ofVec3f v4 = bottomLeft; ofVec3f v1N, v2N, v3N, v4N; v1N = crossProd(v1,v2,v3); v3N = crossProd(v3,v4,v1); v2N = crossProd(v2,v1,v4); v4N = crossProd(v4,v3,v2); mesh.addVertex(v4); mesh.addNormal(v4N); mesh.addVertex(v1); mesh.addNormal(v1N); mesh.addVertex(v2); mesh.addNormal(v2N); mesh.addVertex(v3); mesh.addNormal(v3N); }