Advertisement
drockw2

Untitled

Nov 20th, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.     i0=0;
  3.     i1=1;
  4.     i2=2;
  5.     var n;
  6.     normals = [];
  7.    
  8.     for (n = 0; n < vertices.length; n++)
  9.         normals.push([0,0,0]);
  10.  
  11.    
  12.     for (i= 0; i<triangles.length; i++) {
  13.         triangle = triangles[i];
  14.         a = normalize(sub(vertices[triangle[i1]] , vertices[triangle[i0]]));
  15.         b = normalize(sub(vertices[triangle[i2]] , vertices[triangle[i0]]));
  16.  
  17.         n = normalize(mult(a,b));
  18.        
  19.         normals[i0] = add(normals[i0], n);
  20.         normals[i1] = add(normals[i1], n);
  21.         normals[i2] = add(normals[i2], n);
  22.        
  23.        
  24.     }
  25.    
  26.     for (n= 0; n < normals.length; n++) {
  27.         normals[n] = normalize(normals[n]);
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement