//Universal function which sets normals for the triangle mesh void ofxOcean::setNormals( ofMesh &mesh ){ //The number of the vertices int nV = mesh.getNumVertices(); //The number of the triangles int nT = mesh.getNumIndices() / 3; vector<ofPoint> norm( nV ); //Array for the normals //Scan all the triangles. For each triangle add its //normal to norm's vectors of triangle's vertices for (int t=0; t<nT; t++) { //Get indices of the triangle t int i1 = mesh.getIndex( 3 * t ); int i2 = mesh.getIndex( 3 * t + 1 ); int i3 = mesh.getIndex( 3 * t + 2 ); //Get vertices of the triangle const ofPoint &v1 = mesh.getVertex( i1 ); const ofPoint &v2 = mesh.getVertex( i2 ); const ofPoint &v3 = mesh.getVertex( i3 ); //Compute the triangle's normal ofPoint dir = ( (v2 - v1).getCrossed( v3 - v1 ) ).getNormalized(); //Accumulate it to norm array for i1, i2, i3 norm[ i1 ] += dir; norm[ i2 ] += dir; norm[ i3 ] += dir; } //Normalize the normal's length for (int i=0; i<nV; i++) { norm[i].normalize(); } //Set the normals to mesh mesh.clearNormals(); mesh.addNormals( norm ); }
void PyramidBrush::setNormals(ofMesh& mesh) { int nV = mesh.getNumVertices(); int nT = mesh.getNumIndices() / 3; vector<ofPoint> norm(nV); for(int t=0; t < nT; t++) { int i1 = mesh.getIndex(3*t); int i2 = mesh.getIndex(3*t + 1); int i3 = mesh.getIndex(3*t + 2); const ofPoint &v1 = mesh.getVertex(i1); const ofPoint &v2 = mesh.getVertex(i2); const ofPoint &v3 = mesh.getVertex(i3); ofPoint dir = ( (v2 - v1).crossed(v3 - v1)).normalized(); norm[i1] += dir; norm[i2] += dir; norm[i3] += dir; } for(int i = 0; i < nV; i++) { norm[i].normalize(); } mesh.clearNormals(); mesh.addNormals(norm); }
//-------------------------------------------------------------- //Universal function which sets normals for the triangle mesh void setNormals( ofMesh &mesh ){ int nV = mesh.getNumVertices();//640 int nT = mesh.getNumIndices() / 3;//213 vector<ofPoint> norm( nV ); for (int t=0; t<nT; t++) { int i1 = mesh.getIndex( 3 * t ); int i2 = mesh.getIndex( 3 * t + 1 ); int i3 = mesh.getIndex( 641 ); const ofPoint &v1 = mesh.getVertex( i1 ); const ofPoint &v2 = mesh.getVertex( i2 ); const ofPoint &v3 = mesh.getVertex( i3 ); //Compute the triangle's normal ofPoint dir = ( (v2 - v1).crossed( v3 - v1 ) ).normalized(); norm[ i1 ] += dir; norm[ i2 ] += dir; norm[ i3 ] += dir; } //Normalize the normal's length for (int i=0; i<nV; i++) { norm[i].normalize(); } //Set the normals to mesh mesh.clearNormals(); mesh.addNormals( norm ); }
void buildNormalsFaces(ofMesh& mesh) { mesh.clearNormals(); for(int i = 0; i < mesh.getNumVertices(); i += 3) { int i0 = i + 0, i1 = i + 1, i2 = i + 2; ofVec3f normal = getNormal(mesh.getVertices()[i0], mesh.getVertices()[i1], mesh.getVertices()[i2]); for(int j = 0; j < 3; j++) { mesh.addNormal(normal); } } }