void getCellMesh(voro::voronoicell &_c, ofPoint _pos, ofVboMesh& _mesh, bool bWireframe){ if( _c.p ) { if( !bWireframe ) { // Extract Verteces // ofVboMesh mesh; mesh.setMode(OF_PRIMITIVE_TRIANGLES ); mesh.addVertices(getCellVerteces(_c, _pos)); // Add triangles using Indeces // int k,l,m,n; for(int i = 1; i < _c.p; i++){ for(int j = 0; j < _c.nu[i]; j++) { k = _c.ed[i][j]; if( k >= 0 ) { _c.ed[i][j]=-1-k; l = _c.cycle_up( _c.ed[i][ _c.nu[i]+j], k); m = _c.ed[k][l]; _c.ed[k][l]=-1-m; while(m!=i) { n = _c.cycle_up( _c.ed[k][ _c.nu[k]+l],m); mesh.addTriangle(i, k, m); k=m; l=n; m=_c.ed[k][l]; _c.ed[k][l]=-1-m; } } } } // Calculate Normals // _mesh.setMode(OF_PRIMITIVE_TRIANGLES); vector<ofMeshFace> faces = mesh.getUniqueFaces(); for (int i = 0; i < faces.size(); i++) { ofMeshFace face = faces[i]; ofPoint a = face.getVertex(0); ofPoint b = face.getVertex(1); ofPoint c = face.getVertex(2); ofPoint normal = ((b - a).cross(c - a)).normalize() * -1.; _mesh.addVertex(a); _mesh.addNormal(normal); _mesh.addVertex(b); _mesh.addNormal(normal); _mesh.addVertex(c); _mesh.addNormal(normal); // add texture coordinates if( i % 2 == 0) { _mesh.addTexCoord(ofVec2f(0.0, 0.0)); _mesh.addTexCoord(ofVec2f(0.0, 1.0)); _mesh.addTexCoord(ofVec2f(1.0, 0.0)); } else { _mesh.addTexCoord(ofVec2f(1.0, 0.0)); _mesh.addTexCoord(ofVec2f(0.0, 1.0)); _mesh.addTexCoord(ofVec2f(1.0, 1.0)); } } } else { // wireframe _mesh.setMode(OF_PRIMITIVE_LINES); _mesh.addVertices(getCellVerteces(_c, _pos)); for(int i = 1; i < _c.p; i++){ for(int j = 0; j < _c.nu[i]; j++) { int k = _c.ed[i][j]; if( k >= 0 ) { _mesh.addIndex(i); _mesh.addIndex(k); } } } } } }
//-------------------------------------------------------------- void ofApp::draw(){ delauMesh.setMode(OF_PRIMITIVE_TRIANGLES); delauMesh.draw(); }