Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- i0=0;
- i1=1;
- i2=2;
- var n;
- normals = [];
- for (n = 0; n < vertices.length; n++)
- normals.push([0,0,0]);
- for (i= 0; i<triangles.length; i++) {
- triangle = triangles[i];
- a = normalize(sub(vertices[triangle[i1]] , vertices[triangle[i0]]));
- b = normalize(sub(vertices[triangle[i2]] , vertices[triangle[i0]]));
- n = normalize(mult(a,b));
- normals[i0] = add(normals[i0], n);
- normals[i1] = add(normals[i1], n);
- normals[i2] = add(normals[i2], n);
- }
- for (n= 0; n < normals.length; n++) {
- normals[n] = normalize(normals[n]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement